Skip to content

fix(ui): give brand avatars a light backdrop for transparent logos - #2

Merged
gkhngyk merged 1 commit into
mainfrom
fix/avatar-bg-for-transparent-logos
May 7, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/avatar-bg-for-transparent-logos

Conversation

@gkhngyk

@gkhngyk gkhngyk commented May 7, 2026

Copy link
Copy Markdown
Contributor

Many brand favicons fetched via getFaviconUrl arrive as transparent
PNGs. Without a backdrop, the transparent areas blended into whatever
sits behind the avatar (gradient hero, sidebar bg, etc.) and the logo
looked broken or invisible.

Adds a soft light bg (zinc-50 light / zinc-100 dark) and applies
object-contain + small padding to the AvatarImage so the logo sits
nicely centered with consistent breathing room across:

  • Sidebar BrandSwitcher trigger and dropdown items
  • Brand detail layout header
  • Brand cards hero on /dashboard/brands
  • BrandGuard's brand picker fallback

Fallback initials retain their existing primary-tinted background.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Many brand favicons fetched via getFaviconUrl arrive as transparent
PNGs. Without a backdrop, the transparent areas blended into whatever
sits behind the avatar (gradient hero, sidebar bg, etc.) and the logo
looked broken or invisible.

Adds a soft light bg (zinc-50 light / zinc-100 dark) and applies
object-contain + small padding to the AvatarImage so the logo sits
nicely centered with consistent breathing room across:

  - Sidebar BrandSwitcher trigger and dropdown items
  - Brand detail layout header
  - Brand cards hero on /dashboard/brands
  - BrandGuard's brand picker fallback

Fallback initials retain their existing primary-tinted background.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@vercel

vercel Bot commented May 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ansvisor Ready Ready Preview, Comment May 7, 2026 4:33pm

Request Review

@gkhngyk
gkhngyk merged commit 910fe22 into main May 7, 2026
1 check passed
@gkhngyk
gkhngyk deleted the fix/avatar-bg-for-transparent-logos branch May 7, 2026 16:37
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…e brand's place and its sales from AI (Product Visibility, part 3) (#1638)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…ts, orders and readiness (Product Visibility, part 4) (#1639)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
… on it, top rival and AI revenue (Product Visibility, part 5) (#1640)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…AI picked another one (Product Visibility, part 6) (#1641)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…h the work that gets it on the AI shelf (Product Visibility, part 7) (#1642)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…by channel and check by check (Product Visibility, part 8) (#1643)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…Products chip (Product Visibility, part 9) (#1644)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…nd open the product on that shelf (Product Visibility, part 10) (#1645)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…he product and its category (Product Visibility, part 11) (#1646)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…tarter and 50,000 on Growth (Product Visibility, part 12) (#1647)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* feat(catalog): cap a workspace's catalog products by plan, 50 / 500 / custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* test(catalog): cap a Google Merchant Center account's products by plan, as a feed's

Merchant Center (#1270) reads through the workspace sign-in, a path of
its own beside feeds and stores; the plan's product cap (productRoom)
applies to it all the same.

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

* fix(catalog): cap catalog products at 5,000 on Starter and 50,000 on Growth

ECOM-019's caps were the spec's open-question defaults, 50 and 500: a
real store's catalog went past them on the first sync. Decided on
2026-10-28: Starter 5,000, Growth 50,000; Enterprise stays set per
customer through plan_overrides, and self-hosted uncapped (both -1).

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…swers that showed it (Product Visibility, part 13) (#1648)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* feat(catalog): cap a workspace's catalog products by plan, 50 / 500 / custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

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

* feat(shopping): show what AI says about a product, quoted from the answers that showed it (product visibility, part 13)

ECOM-012, V1. A product's page gets a "What AI says" card: from the
answers of the last 30 days whose cards showed the product, the sentence
that names it (as Mentions quotes a brand: answerProse, mentionExcerpt),
the latest first, one per text, and the sources those answers cited most.
Their own words only: no AI of ours reads them, so no cost. Pros and cons
drawn from them come later.

- lib/shopping/ai-says.ts: productNames (each card title and its name
  before the variant), productQuote, productAiSays.
- getProductAiSays reads the product's cards, then the latest 8 answers'
  text and the latest 20's citations; the page reads it apart and fills the
  card when it comes, so the heavy text doesn't hold the page.
- mention-match: namesAny, the tracking match as a yes/no.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* test(catalog): cap a Google Merchant Center account's products by plan, as a feed's

Merchant Center (#1270) reads through the workspace sign-in, a path of
its own beside feeds and stores; the plan's product cap (productRoom)
applies to it all the same.

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

* fix(catalog): cap catalog products at 5,000 on Starter and 50,000 on Growth

ECOM-019's caps were the spec's open-question defaults, 50 and 500: a
real store's catalog went past them on the first sync. Decided on
2026-10-28: Starter 5,000, Growth 50,000; Enterprise stays set per
customer through plan_overrides, and self-hosted uncapped (both -1).

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…ith a Shopping filter (Product Visibility, part 14) (#1649)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* feat(catalog): cap a workspace's catalog products by plan, 50 / 500 / custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

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

* feat(shopping): show what AI says about a product, quoted from the answers that showed it (product visibility, part 13)

ECOM-012, V1. A product's page gets a "What AI says" card: from the
answers of the last 30 days whose cards showed the product, the sentence
that names it (as Mentions quotes a brand: answerProse, mentionExcerpt),
the latest first, one per text, and the sources those answers cited most.
Their own words only: no AI of ours reads them, so no cost. Pros and cons
drawn from them come later.

- lib/shopping/ai-says.ts: productNames (each card title and its name
  before the variant), productQuote, productAiSays.
- getProductAiSays reads the product's cards, then the latest 8 answers'
  text and the latest 20's citations; the page reads it apart and fills the
  card when it comes, so the heavy text doesn't hold the page.
- mention-match: namesAny, the tracking match as a yes/no.

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

* feat(prompts): suggest shopping questions from the brand's catalog, with a Shopping filter (product visibility, part 14)

ECOM-003. A suggestion refresh now also offers the model the brand's
catalog categories, each with its live products and price band (the round
price most of them sell under), and asks for at least 5 shopping questions
from them: best-of, under a budget, for a use, which type. One that names an
offered category is kept with source 'catalog' and the category in
source_data; a category the catalog never offered stays a plain suggestion.
Brands without a catalog get the same prompt as before.

- server/src/lib/catalog-suggestions.js: composeCatalogCandidates,
  roundPrice; any read failure returns [] so a refresh never fails on it.
- 00362: 'catalog' in prompt_suggestions_source_check; schema.sql rebuilt.
- Prompt Suggestions: a "Your catalog" badge with the category on hover,
  and a Shopping source filter once the catalog gave a suggestion (or
  ?source=shopping); "Ansvisor Agents only" leaves them out.
- docs/guides/prompts.mdx: the fourth source.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* test(catalog): cap a Google Merchant Center account's products by plan, as a feed's

Merchant Center (#1270) reads through the workspace sign-in, a path of
its own beside feeds and stores; the plan's product cap (productRoom)
applies to it all the same.

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

* fix(catalog): cap catalog products at 5,000 on Starter and 50,000 on Growth

ECOM-019's caps were the spec's open-question defaults, 50 and 500: a
real store's catalog went past them on the first sync. Decided on
2026-10-28: Starter 5,000, Growth 50,000; Enterprise stays set per
customer through plan_overrides, and self-hosted uncapped (both -1).

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…der parallel syncs, and count suggestion categories in SQL (Product Visibility follow-ups, part 1) (#1665)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* feat(catalog): cap a workspace's catalog products by plan, 50 / 500 / custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

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

* feat(shopping): show what AI says about a product, quoted from the answers that showed it (product visibility, part 13)

ECOM-012, V1. A product's page gets a "What AI says" card: from the
answers of the last 30 days whose cards showed the product, the sentence
that names it (as Mentions quotes a brand: answerProse, mentionExcerpt),
the latest first, one per text, and the sources those answers cited most.
Their own words only: no AI of ours reads them, so no cost. Pros and cons
drawn from them come later.

- lib/shopping/ai-says.ts: productNames (each card title and its name
  before the variant), productQuote, productAiSays.
- getProductAiSays reads the product's cards, then the latest 8 answers'
  text and the latest 20's citations; the page reads it apart and fills the
  card when it comes, so the heavy text doesn't hold the page.
- mention-match: namesAny, the tracking match as a yes/no.

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

* feat(prompts): suggest shopping questions from the brand's catalog, with a Shopping filter (product visibility, part 14)

ECOM-003. A suggestion refresh now also offers the model the brand's
catalog categories, each with its live products and price band (the round
price most of them sell under), and asks for at least 5 shopping questions
from them: best-of, under a budget, for a use, which type. One that names an
offered category is kept with source 'catalog' and the category in
source_data; a category the catalog never offered stays a plain suggestion.
Brands without a catalog get the same prompt as before.

- server/src/lib/catalog-suggestions.js: composeCatalogCandidates,
  roundPrice; any read failure returns [] so a refresh never fails on it.
- 00362: 'catalog' in prompt_suggestions_source_check; schema.sql rebuilt.
- Prompt Suggestions: a "Your catalog" badge with the category on hover,
  and a Shopping source filter once the catalog gave a suggestion (or
  ?source=shopping); "Ansvisor Agents only" leaves them out.
- docs/guides/prompts.mdx: the fourth source.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* test(catalog): cap a Google Merchant Center account's products by plan, as a feed's

Merchant Center (#1270) reads through the workspace sign-in, a path of
its own beside feeds and stores; the plan's product cap (productRoom)
applies to it all the same.

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

* fix(catalog): cap catalog products at 5,000 on Starter and 50,000 on Growth

ECOM-019's caps were the spec's open-question defaults, 50 and 500: a
real store's catalog went past them on the first sync. Decided on
2026-10-28: Starter 5,000, Growth 50,000; Enterprise stays set per
customer through plan_overrides, and self-hosted uncapped (both -1).

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

* fix(catalog): match a brand's shopping cards right after a sync the person asked for

A catalog connected, synced from Settings or uploaded had its brand's AI
shopping cards matched only by the next day's sweep, so the Shelf showed
"Products on the shelf" at 0 for a day. After such a sync reads the
catalog, matchBrandLater matches the brand's recent cards in the
background: never waited on, a failure logged, and a brand being matched
already matched once more after instead of twice at once.

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

* fix(catalog): write a workspace's capped catalog sources one at a time

Two sources of one workspace synced at once (a sync from Settings while
the daily run reads another store) each counted the room the other was
about to take, and could keep more products than the plan's cap. On the
managed cloud the room count and the writes now wait in a line per
organization (inLine); the store or feed read itself doesn't. The comment
explains how products marked removed past the cap meet the 90-day purge.

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

* perf(prompts): count catalog categories for shopping suggestions in the database

Shopping prompt suggestions read every live product, category link and
variant of the brand's catalog, a page at a time, to offer 8 categories,
and cut the categories at an arbitrary 1,000. 00371 adds
catalog_suggestion_categories, which counts each category's live products
and its price band in SQL and returns only the categories offered; the
server rounds the 75th-percentile price as before.

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

* fix(catalog): keep uncapped workspaces out of the write line, and stop waiting for a stuck write

Every cloud workspace's catalog writes waited in its line, even on a plan
without a cap, where there is no room to count; and a write that never
finished held its workspace's line for good. The cap is now read first,
and only a capped workspace's sources wait in line. A write waits five
minutes at most (LINE_WAIT_MS) for the one before it, then runs anyway,
recounting its room on its turn, and the stopped wait is logged.

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

* perf(prompts): read only the brand's live products when counting its suggestion categories

catalog_suggestion_categories (00371) joined a category link to its
product by id alone, so the live-product filter couldn't use
catalog_products_brand_live_idx. The join now names the brand too.
schema.sql is rebuilt.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

* perf(prompts): read only the brand's live variants when pricing its suggestion categories (00371)

The variants half of 00371's read now filters by brand and live rows, as
the products half does, so catalog_variants_brand_live_idx (00281) serves
it rather than every brand's variants.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…rom every channel, and leave an unknown check out of the score (Product Visibility follow-ups, part 2) (#1666)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* feat(catalog): cap a workspace's catalog products by plan, 50 / 500 / custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

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

* feat(shopping): show what AI says about a product, quoted from the answers that showed it (product visibility, part 13)

ECOM-012, V1. A product's page gets a "What AI says" card: from the
answers of the last 30 days whose cards showed the product, the sentence
that names it (as Mentions quotes a brand: answerProse, mentionExcerpt),
the latest first, one per text, and the sources those answers cited most.
Their own words only: no AI of ours reads them, so no cost. Pros and cons
drawn from them come later.

- lib/shopping/ai-says.ts: productNames (each card title and its name
  before the variant), productQuote, productAiSays.
- getProductAiSays reads the product's cards, then the latest 8 answers'
  text and the latest 20's citations; the page reads it apart and fills the
  card when it comes, so the heavy text doesn't hold the page.
- mention-match: namesAny, the tracking match as a yes/no.

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

* feat(prompts): suggest shopping questions from the brand's catalog, with a Shopping filter (product visibility, part 14)

ECOM-003. A suggestion refresh now also offers the model the brand's
catalog categories, each with its live products and price band (the round
price most of them sell under), and asks for at least 5 shopping questions
from them: best-of, under a budget, for a use, which type. One that names an
offered category is kept with source 'catalog' and the category in
source_data; a category the catalog never offered stays a plain suggestion.
Brands without a catalog get the same prompt as before.

- server/src/lib/catalog-suggestions.js: composeCatalogCandidates,
  roundPrice; any read failure returns [] so a refresh never fails on it.
- 00362: 'catalog' in prompt_suggestions_source_check; schema.sql rebuilt.
- Prompt Suggestions: a "Your catalog" badge with the category on hover,
  and a Shopping source filter once the catalog gave a suggestion (or
  ?source=shopping); "Ansvisor Agents only" leaves them out.
- docs/guides/prompts.mdx: the fourth source.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* test(catalog): cap a Google Merchant Center account's products by plan, as a feed's

Merchant Center (#1270) reads through the workspace sign-in, a path of
its own beside feeds and stores; the plan's product cap (productRoom)
applies to it all the same.

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

* fix(catalog): cap catalog products at 5,000 on Starter and 50,000 on Growth

ECOM-019's caps were the spec's open-question defaults, 50 and 500: a
real store's catalog went past them on the first sync. Decided on
2026-10-28: Starter 5,000, Growth 50,000; Enterprise stays set per
customer through plan_overrides, and self-hosted uncapped (both -1).

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

* fix(catalog): match a brand's shopping cards right after a sync the person asked for

A catalog connected, synced from Settings or uploaded had its brand's AI
shopping cards matched only by the next day's sweep, so the Shelf showed
"Products on the shelf" at 0 for a day. After such a sync reads the
catalog, matchBrandLater matches the brand's recent cards in the
background: never waited on, a failure logged, and a brand being matched
already matched once more after instead of twice at once.

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

* fix(catalog): write a workspace's capped catalog sources one at a time

Two sources of one workspace synced at once (a sync from Settings while
the daily run reads another store) each counted the room the other was
about to take, and could keep more products than the plan's cap. On the
managed cloud the room count and the writes now wait in a line per
organization (inLine); the store or feed read itself doesn't. The comment
explains how products marked removed past the cap meet the 90-day purge.

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

* perf(prompts): count catalog categories for shopping suggestions in the database

Shopping prompt suggestions read every live product, category link and
variant of the brand's catalog, a page at a time, to offer 8 categories,
and cut the categories at an arbitrary 1,000. 00371 adds
catalog_suggestion_categories, which counts each category's live products
and its price band in SQL and returns only the categories offered; the
server rounds the 75th-percentile price as before.

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

* fix(shopping): leave the first-40-words check out of readiness when a product has no type

Shopify often leaves product_type empty, and a product with neither a
type nor a category failed "what the product is in the first 40 words"
for want of a word to look for. Its readiness now counts that check as
unknown: left out of the score (out of the other checks' points), said
apart in the Products tooltip and on the product page, not counted in
Readiness's First 40 words check, which is unknown when no product has
a type. An empty type falls back to the category as a missing one did.

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

* fix(shopping): recover the Shelf from a failed read, and read Readiness's channels from every channel

- Shelf: a read that failed left its numbers and rows on a skeleton for
  good. It now says so with a Try again button that reads it again.
- The orders from AI visits are kept by brand: switching brands no longer
  shows the last brand's AI revenue while the new one's are read; the
  revenue and top-channel numbers wait for them instead.
- Readiness: the channel cards read every channel's shelves whatever
  channel the Shelf's chips picked, so a card no longer says "Tracked,
  yours not shown" because another channel was chosen. They wait while
  read, and say "Couldn't read" when they couldn't be.
- The price bands are named in the shelves' own currency ("Under €50"),
  a cut KPI value shows whole on hover, and a long channel name wraps in
  a narrow Readiness card.

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

* fix(catalog): keep uncapped workspaces out of the write line, and stop waiting for a stuck write

Every cloud workspace's catalog writes waited in its line, even on a plan
without a cap, where there is no room to count; and a write that never
finished held its workspace's line for good. The cap is now read first,
and only a capped workspace's sources wait in line. A write waits five
minutes at most (LINE_WAIT_MS) for the one before it, then runs anyway,
recounting its room on its turn, and the stopped wait is logged.

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

* perf(prompts): read only the brand's live products when counting its suggestion categories

catalog_suggestion_categories (00371) joined a category link to its
product by id alone, so the live-product filter couldn't use
catalog_products_brand_live_idx. The join now names the brand too.
schema.sql is rebuilt.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

* perf(prompts): read only the brand's live variants when pricing its suggestion categories (00371)

The variants half of 00371's read now filters by brand and live rows, as
the products half does, so catalog_variants_brand_live_idx (00281) serves
it rather than every brand's variants.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…e, and an honest 7-day re-check (Product Visibility follow-ups, part 3) (#1667)

* feat(shopping): open Product Visibility with its data sources, a Why popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

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

* feat(shopping): match each AI shopping card to the brand's catalog product it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

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

* feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

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

* feat(shopping): list the catalog's products with their AI shelf, visits, orders and readiness (product visibility, part 4)

The Products tab (ECOM-007) lists the brand's catalog when it has one.
Each product shows:
- its photo, category and price;
- the AI shelves it was on, its win rate (#1 or #2) and average place
  over the filter window, from its matched cards (00360);
- the AI visits its page got;
- the orders those visits led to, and their revenue;
- its readiness out of 100.

Visits and orders come from catalog_product_ai_stats (00361). No source
carries order line items yet (Shopify order sync, #1267), so an order is
credited to the product whose page the AI visitor landed on first
(ai_traffic_events.first_url). A product's page is its link, else its
first variant's, matched by path. Members of the brand's organization
only.

Readiness adds up what the catalog can tell:
- a GTIN (20);
- a photo (15);
- in stock (15);
- a price (10);
- a description of 25 words or more (15);
- what the product is, in its first 40 words (10, ECOM-024);
- a category (10);
- a brand (5).
Its tip says what's missing and what each costs.

Views: All, Never shown, Shown not clicked, Clicked not bought, and Top
sellers from AI, each with its count. The table reads up to 2,000
products and says so past that. A brand with no catalog, or one that
can't be read, keeps the products AI showed by title, with a line on
connecting the catalog. Prices format in one place
(lib/shopping/price.ts).

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

* feat(shopping): show each catalog category's AI shelf share, products on it, top rival and AI revenue (product visibility, part 5)

The Categories tab (ECOM-008, between Shelf and Products) lists each
category of the brand's catalog that has live products, with:
- its shopping questions: a question is the category's when the
  category's own name is in it (its last level, plural or not:
  "Hiking backpacks" in "lightweight 30L hiking backpack for women"),
  or when one of its products was on the question's shelf (00360);
- the brand's share of the product slots on those shelves, with a bar;
- its products on a shelf, of its products;
- the rival with the most slots there: the competitor a card is
  matched to, else the card's brand, with its favicon;
- its products' AI revenue in their main currency (00361).

A category with three questions or more where the brand holds under 10%
of the slots is marked "needs attention", tinted amber. The tab reads
when it opens, once per brand and filters, and shows its count. It also
says when the catalog has no categories, or when they can't be read.

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

* feat(shopping): give each product a page with where it shows and why AI picked another one (product visibility, part 6)

Each product in the Products table now opens its own page,
/dashboard/shopping/products/[id] (ECOM-011, the mockup's product
detail).

Header: its photo, price, category, "On N of M shelves", its
readiness, and "View product page". Below it, its AI clicks, AI orders
and AI revenue over 30 days (00361).

"Why not your product?": for the most relevant question whose shelf it
isn't on (else the one it ranks lowest on), it stands beside the
product AI put first, row by row:
- match with the question: both BM25 scores (#1487's), over its title
  and its description's first 40 words, with the missing words;
- price: close, or how much higher or lower;
- rating and reviews, as the answers showed them;
- what it is, in its first 40 words;
- GTIN, photo and stock in the feed;
- who sells each.
Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what
each has. Rows we have no data for (delivery, returns, schema) are left
out rather than guessed.

"Where it shows": the questions it belongs on (its category's name in
them, the shelves it was on, or a match of 40 or more), each channel's
latest shelf, its place, its match and the missing words. Then its
readiness, check by check.

The view is its own component (_product-detail.tsx). Reading the
catalog's products is shared with the Products table. The plan's
locked note now says what Growth unlocks here.

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

* feat(shopping): send a product or a category to the Action Center with the work that gets it on the AI shelf (product visibility, part 7)

ECOM-013, the mockup's "Actions to get on the shelf" and "Category
actions".

A product's page lists its proposed work, from what it misses beside the
shelf's winner:
- Optimize page: rewrite it for the missing words;
- Create content: a comparison with the winner and an FAQ, else a
  buying guide;
- Get listed: the review sites AI quotes;
- Technical: GTIN and structured data.

The Categories table's "Plan actions" (filled on a category that needs
attention) opens the same for the category: the category page, a buying
guide, the "best X" lists, and its feed fields.

Each line is picked or not and set to Me or Agent. The agent can't take
a technical fix. "Send N actions to Action Center" opens one action with
a toast that links to it; a second send returns the action still open.

Server, POST /api/action-center/products (lib/action-center/
from-products.js):
- a 'shopping_product' (Growth) or 'shopping_category' (Compete) action,
  one open per product or category;
- tasks from the library: optimize_content; create_content_brief +
  create_content_draft; prepare_outreach + execute_outreach;
  fix_structured_data. Each task's mode follows Me or Agent where the
  task allows it, and the line becomes its why;
- the payload keeps the brand's own questions only. It's measured on
  them and the product's page (basket metrics), with its own priority
  subject.

The web knows both kinds' titles ("Get Ridge 30L Backpack on the shelf",
"Win “Hiking backpacks” in AI answers"). A category row keeps its
questions' ids.

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

* feat(shopping): score how ready the shop is for AI shopping, channel by channel and check by check (product visibility, part 8)

The Readiness tab (ECOM-015, spec §3.4 / §3.4b, the mockup's Readiness):
- the market and what it means for ChatGPT: OpenAI's product index in
  the US, Google Shopping in Europe;
- one card per AI shopping channel (ChatGPT Shopping, Google AI
  Overviews, AI Mode, Gemini, Copilot): whether it shows the brand's
  products, has its shelves tracked without them, or isn't tracked, and
  where it takes products from;
- "AI shopping readiness" scored 0–100.

The checklist lists only what Ansvisor can read:
- the catalog, and the Merchant Center feed (a fail in Europe, where it
  decides ChatGPT too);
- in the US, OpenAI's product index, and the verified seller flag as
  unknown, not scored;
- descriptions that don't say what the product is in their first 40
  words;
- feed fields complete (GTIN, photo, price, brand, category);
- feed links tagged utm_medium=feed;
- a price an AI answer shows more than 2% off the catalog's, with an
  example;
- resellers cheaper than the brand;
- Amazon's share falling sharply.

Product page schema, return policies, AI bots on product pages and
colors as separate items aren't listed until there's data for them. Each
check says where its fix starts: the Products table, or Settings ›
Integrations. OpenAI's product index card, with its direct-feed switch,
moves from Shelf to here.

The Products read keeps the prices AI answers showed for each matched
product, for the wrong price check.

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

* feat(action-center): list the actions sent from Products with a From Products chip (product visibility, part 9)

The ECOM mockup's Action Center preview: a "From Products" chip beside
the categories, for the actions Product Visibility sends (part 7): a
product to get on the AI shelf ('shopping_product', Growth) and a
category to win ('shopping_category', Compete). They sit in different
categories, so no category filter shows them together.

- The chip shows with its count when the brand has such an action, and
  filters the list (and its CSV export) to them, whatever the category;
  a second click clears it.
- It lives in the URL (?from=products) with the page's other filters.
- FROM_PRODUCTS_KINDS in lib/action-center/registry.ts names the kinds.

The action-center guide says so.

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

* feat(shopping): offer "Why not you?" on a shelf the brand isn't on, and open the product on that shelf (product visibility, part 10)

The mockup's Shelf: "When you're absent, your product shows greyed with
'Why not you? ›', which opens the product detail."

- On a shelf the brand isn't on, its product the question asks for most
  shows greyed after the shelf's own cards (the last of six gives way):
  whyNotYou in lib/shopping/shelf.ts scores the catalog's products by the
  question's words in their title, category and type, the readier one on
  a tie, none when nothing shares a word. Read from the Products table's
  rows, which load with the Shelf: no new read.
- "Why not you? ›" opens the product's page on that shelf
  (?prompt=…&platform=…): getShoppingProductDetail takes the shelf asked
  for, keeps its question whatever its match (productShelves' include) and
  explains it first (focusShelf's prefer), beside the product AI picked
  there. Without one, or when the brand leads it, the page explains its
  usual shelf.

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

* feat(shopping): show what a done Products action did, 7 days on, on the product and its category (product visibility, part 11)

ECOM-018. Once an action sent from Products is completed, the product's
page and the Categories table set the shelves of its shopping questions in
the 7 days after it was done beside the 7 days before: how many the product
(or, for a category, any of the brand's products) was on. Read from the
cards already kept when the page opens: no job, nothing stored.

- lib/shopping/recheck.ts: shelfPresence, actionResult, resultTrend.
- getShoppingProductDetail reads the product's last done action beside the
  rest; one that can't be read leaves the page as it is.
- getShoppingActionResults: the categories' results, read after the table.
- Product page: an "After action #N" card with Open the action; the
  Categories table: a line under the category's name.

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

* feat(catalog): cap a workspace's catalog products by plan, 50 / 500 / custom (product visibility, part 12)

ECOM-019. Plans get maxCatalogProducts: Starter 50, Growth 500,
Enterprise set per customer through plan_overrides, self-hosted no cap;
counted across the workspace's brands, like prompts.

- On the managed cloud a source's sync keeps what's left of the cap after
  the workspace's other sources (productRoom): the products already live
  first, so a tracked product stays tracked, then the new ones in the
  source's order. The rest aren't written; one in the catalog already is
  marked removed, as if gone from the source, and comes back when there's
  room. Nothing is deleted.
- The source records how many it couldn't keep and the cap (last_counts
  overLimit / limit); Settings › Product catalog says so, with Upgrade for
  admins and managers.
- A workspace without an active subscription gets the plan's own words.

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

* feat(shopping): show what AI says about a product, quoted from the answers that showed it (product visibility, part 13)

ECOM-012, V1. A product's page gets a "What AI says" card: from the
answers of the last 30 days whose cards showed the product, the sentence
that names it (as Mentions quotes a brand: answerProse, mentionExcerpt),
the latest first, one per text, and the sources those answers cited most.
Their own words only: no AI of ours reads them, so no cost. Pros and cons
drawn from them come later.

- lib/shopping/ai-says.ts: productNames (each card title and its name
  before the variant), productQuote, productAiSays.
- getProductAiSays reads the product's cards, then the latest 8 answers'
  text and the latest 20's citations; the page reads it apart and fills the
  card when it comes, so the heavy text doesn't hold the page.
- mention-match: namesAny, the tracking match as a yes/no.

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

* feat(prompts): suggest shopping questions from the brand's catalog, with a Shopping filter (product visibility, part 14)

ECOM-003. A suggestion refresh now also offers the model the brand's
catalog categories, each with its live products and price band (the round
price most of them sell under), and asks for at least 5 shopping questions
from them: best-of, under a budget, for a use, which type. One that names an
offered category is kept with source 'catalog' and the category in
source_data; a category the catalog never offered stays a plain suggestion.
Brands without a catalog get the same prompt as before.

- server/src/lib/catalog-suggestions.js: composeCatalogCandidates,
  roundPrice; any read failure returns [] so a refresh never fails on it.
- 00362: 'catalog' in prompt_suggestions_source_check; schema.sql rebuilt.
- Prompt Suggestions: a "Your catalog" badge with the category on hover,
  and a Shopping source filter once the catalog gave a suggestion (or
  ?source=shopping); "Ansvisor Agents only" leaves them out.
- docs/guides/prompts.mdx: the fourth source.

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

* fix(shopping): read a re-check's cards a hundred question ids at a time

The categories' re-check could filter one card read by up to 400 question
ids, a request address long enough to be refused. Reads now take 100 ids
each, side by side.

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

* fix(catalog): index a shopping card's catalog product by itself, for a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

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

* perf(catalog): match a big catalog's cards without holding the event loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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

* fix(shopping): read every product's AI visits, and list a big catalog's active products first (00361)

catalog_product_ai_stats returned a row for every live product, so a
catalog past 1000 products lost the rest to PostgREST's max_rows, and the
Products table read at most the first 2000 products by id, with every
variant of the catalog.

- 00361 returns only the products with an AI visit or an order, and takes
  p_product_id for one product's row. The table reads it a page at a time
  (readAllRpcRows, by product_id).
- Past 2000 products, the table lists those on a shelf or visited from AI
  first (orders, then shelves, then visits), then the rest by id. Their
  rows, variants, photos and categories are read for those ids, 100 at a
  time; a catalog of 2000 or fewer is read by the brand, as before.
- All and Never shown count the whole catalog (the server's count), not
  the rows read; the note says which products the table holds.

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

* perf(shopping): read the Products table only on its tab, and the Shelf apart from the rest

Each filter change read the whole Products table with the page's other
reads, and the Shelf's rows waited for all of them.

- useKeyedRead: a read made once per brand and filters while it's wanted,
  an older answer dropped. The Shelf reads with it on its own; the
  Products table only while its tab is open, as Categories does.
- The no-catalog view says what main's CatalogNote says (with its link to
  Settings), not a second line of its own: products.noCatalog goes.

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

* fix(shopping): read every product's AI revenue for the Categories table

The Categories table read catalog_product_ai_stats in one request, so a
catalog with more than 1000 products with AI visits or orders lost the rest
of its revenue to PostgREST's max_rows. It reads the pages now, as the
Products table does (readProductAiStats).

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

* fix(shopping): read a product's page for that product alone

The product's page read every product's AI visits and orders to find its
own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats
for its product only (p_product_id, 00361), and reads its catalog rows by
its id.

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

* fix(shopping): say each "Why not your product?" row's state in words, beside its icon

The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.

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

* fix(action-center): send products to the Action Center on Product Visibility's plans only, and never as an action without tasks

POST /api/action-center/products checked the brand but not the plan, and
opened the action before planning its tasks.

- The route asks for shopping_analytics (requireFeature), as the page does.
- The tasks are planned before the action is inserted. Work none of whose
  tasks can be planned for the brand opens nothing: a 422 that says so,
  shown in the page's toast.
- The other Action Center route tests' plan-guard mocks give requireFeature.

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

* fix(shopping): name each Categories row's Plan actions button for its category

Every row's button read "Plan actions", so a screen reader's list of
buttons couldn't tell them apart. Each is labelled "Plan actions for
Hiking backpacks", its visible text first.

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

* fix(shopping): flag a wrong price in AI answers only from each channel's latest answer, against every variant's price

The Readiness "Wrong price in AI answers" check flagged any card in the
window more than 2% off the product's lowest in-stock price: an older
answer since corrected, or the price of another variant or before a sale,
was flagged as wrong.

- Only each channel's latest card counts (cards now carry when they were
  shown).
- A price is wrong only when it's more than 2% off every variant's price
  and sale price in the same currency (CatalogProductRow.prices; without
  them, the product's price, as before).

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

* fix(shopping): wait for the catalog in Readiness, and say what couldn't be read instead of changing the score

Readiness scored at once, from whatever had been read: while the catalog
sources or products were still loading, or after their read failed, the
checks on them were dropped and the score changed without a word.

- The products are read on the Readiness tab too.
- The checklist and its score show a skeleton until the sources and the
  products are read.
- A read that failed is said in a line above the checks, and the score
  isn't shown until it can be read. Merchant Center is "unknown", not
  "connect it", when the sources couldn't be read.

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

* fix(action-center): keep the From Products chip while its filter is on, to turn it off

Opened from ?from=products with no action from Products left, the list
was filtered to nothing and the chip that turns the filter off wasn't
shown. The chip shows while it's on, with its count of 0.

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

* perf(shopping): read the catalog for the Shelf's "Why not you?" once per brand

"Why not you?" took its product from the Products table, which now reads
only on its tab: on the Shelf the card never showed. The Shelf reads the
catalog's products itself, once per brand and not again on a filter
change (the card needs the products, not the window's numbers), and
without holding up the shelves. The table's own read is used when there.

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

* fix(shopping): start the "Why not you?" link's name with the words it shows

Its aria-label ("Why isn't … on this shelf?") didn't contain its visible
text, so voice control couldn't reach it by what it says. It reads "Why
not you? Open … beside the product AI picked on this shelf".

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

* test(catalog): cap a Google Merchant Center account's products by plan, as a feed's

Merchant Center (#1270) reads through the workspace sign-in, a path of
its own beside feeds and stores; the plan's product cap (productRoom)
applies to it all the same.

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

* fix(catalog): cap catalog products at 5,000 on Starter and 50,000 on Growth

ECOM-019's caps were the spec's open-question defaults, 50 and 500: a
real store's catalog went past them on the first sync. Decided on
2026-10-28: Starter 5,000, Growth 50,000; Enterprise stays set per
customer through plan_overrides, and self-hosted uncapped (both -1).

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

* fix(catalog): match a brand's shopping cards right after a sync the person asked for

A catalog connected, synced from Settings or uploaded had its brand's AI
shopping cards matched only by the next day's sweep, so the Shelf showed
"Products on the shelf" at 0 for a day. After such a sync reads the
catalog, matchBrandLater matches the brand's recent cards in the
background: never waited on, a failure logged, and a brand being matched
already matched once more after instead of twice at once.

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

* fix(catalog): write a workspace's capped catalog sources one at a time

Two sources of one workspace synced at once (a sync from Settings while
the daily run reads another store) each counted the room the other was
about to take, and could keep more products than the plan's cap. On the
managed cloud the room count and the writes now wait in a line per
organization (inLine); the store or feed read itself doesn't. The comment
explains how products marked removed past the cap meet the 90-day purge.

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

* perf(prompts): count catalog categories for shopping suggestions in the database

Shopping prompt suggestions read every live product, category link and
variant of the brand's catalog, a page at a time, to offer 8 categories,
and cut the categories at an arbitrary 1,000. 00371 adds
catalog_suggestion_categories, which counts each category's live products
and its price band in SQL and returns only the categories offered; the
server rounds the 75th-percentile price as before.

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

* fix(shopping): leave the first-40-words check out of readiness when a product has no type

Shopify often leaves product_type empty, and a product with neither a
type nor a category failed "what the product is in the first 40 words"
for want of a word to look for. Its readiness now counts that check as
unknown: left out of the score (out of the other checks' points), said
apart in the Products tooltip and on the product page, not counted in
Readiness's First 40 words check, which is unknown when no product has
a type. An empty type falls back to the category as a missing one did.

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

* fix(shopping): recover the Shelf from a failed read, and read Readiness's channels from every channel

- Shelf: a read that failed left its numbers and rows on a skeleton for
  good. It now says so with a Try again button that reads it again.
- The orders from AI visits are kept by brand: switching brands no longer
  shows the last brand's AI revenue while the new one's are read; the
  revenue and top-channel numbers wait for them instead.
- Readiness: the channel cards read every channel's shelves whatever
  channel the Shelf's chips picked, so a card no longer says "Tracked,
  yours not shown" because another channel was chosen. They wait while
  read, and say "Couldn't read" when they couldn't be.
- The price bands are named in the shelves' own currency ("Under €50"),
  a cut KPI value shows whole on hover, and a long channel name wraps in
  a narrow Readiness card.

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

* fix(shopping): offer "Why not you?" only for a product the question asks for

"Best running shoes for men under $100" offered "Men's Best Seller Tee":
one shared word was enough, and "best", "under" and the price counted.
The question's asking words (best, top, under, cheap, …), numbers and
single letters no longer count, and a product needs two of the question's
words, or a category or type the question names.

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

* fix(shopping): look for a product by its own name in "What AI says", not its brand's

"The North Face | Borealis Backpack" was looked for as "The North Face",
so any sentence about the brand was quoted as the product's. The
product's brand (the catalog's and the cards') is now kept out of its
names: a title part that is the brand is left out, a brand opening a
part is cut off, and the brand alone is never a name.

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

* fix(shopping): read only a product's own questions on its page, never name its brand's own product the winner

- "Why not your product?" named the shelf's first product the winner even
  when it was another of the brand's own; the winner is now the first
  rival above it, none when only the brand's own are.
- An address with no product id in it says the product isn't in the
  catalog, not that the read failed.
- A plan without Product Visibility reads nothing on the page.
- The page read every card of the window with each answer's searches.
  It now reads the product's own cards, the brand's questions, then the
  shelves of up to 60 it may belong on (detailPrompts: asked for, shown
  on, of its category, sharing its words), and AI's searches only for
  each shelf's latest answer.

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

* fix(shopping): re-check every question of a done action, and count a category's own products

- The 7-day re-check read the first 400 questions of the actions it
  checked; it now reads them all, 100 ids a read, six reads at a time.
- A category's shelves counted any of the brand's products; they now
  count the category's own (catalog_product_categories).
- A week after with no answers read shows "not run in the 7 days after"
  in the Categories table instead of "x/y → 0/0".
- A week before with no shelf read is "New: nothing to compare", not
  "On more of its shelves".

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

* perf(shopping): group a re-checked category's products once, not per action

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

* fix(catalog): keep uncapped workspaces out of the write line, and stop waiting for a stuck write

Every cloud workspace's catalog writes waited in its line, even on a plan
without a cap, where there is no room to count; and a write that never
finished held its workspace's line for good. The cap is now read first,
and only a capped workspace's sources wait in line. A write waits five
minutes at most (LINE_WAIT_MS) for the one before it, then runs anyway,
recounting its room on its turn, and the stopped wait is logged.

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

* perf(prompts): read only the brand's live products when counting its suggestion categories

catalog_suggestion_categories (00371) joined a category link to its
product by id alone, so the live-product filter couldn't use
catalog_products_brand_live_idx. The join now names the brand too.
schema.sql is rebuilt.

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

* fix(shopping): don't offer "Why not you?" for a product on who it's for alone

A product whose category or type only said who it's for ("Clothing >
Men", type "Men") counted as the category a question names: "best running
shoes for men under $100" offered a "Men's Best Seller Tee". Words like
men, women or kids no longer make a product a candidate, neither as its
category or type nor toward the two shared words; they still break a tie
between candidates.

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

* fix(shopping): don't compare a done action whose answers were too many to read

The re-check reads its questions' cards newest first, up to CARD_MAX_ROWS
per hundred questions. A read cut there dropped the oldest cards, the week
before the action first, so a product on its shelves before read as "New:
nothing to compare" or "On more of its shelves". An action with a question
in a cut read is now partial: no trend, and its card and line say there
were too many answers to compare.

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

* perf(catalog): bound the work on a long card link or title when matching cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

* perf(shopping): count each question's shelves once for the Categories table

Each category added up its questions' cards by walking every card in the
window again; a big catalog's categories, each in most questions, took
seconds. The cards are now counted once per question (slots, the brand's,
each rival's), and a category adds up its questions. The rows are the same.

* fix(shopping): list a category's questions in the cards' order

Counting each question's shelves once gathers a category's questions by
name first, then by its products. Its promptIds are put back in the
cards' order, so the first 50 sent to the Action Center are the same as
before.

* fix(shopping): send a category's first 50 questions and cut a long work line, as the Action Center route takes them

A category with more than 50 shopping questions, or a work line over 500
characters (a long question or two long product titles), was refused whole
by POST /api/action-center/products with a 400, so nothing was sent. The
web now sends the first 50 questions and cuts the line at a word.

* perf(prompts): read only the brand's live variants when pricing its suggestion categories (00371)

The variants half of 00371's read now filters by brand and live rows, as
the products half does, so catalog_variants_brand_live_idx (00281) serves
it rather than every brand's variants.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk pushed a commit that referenced this pull request Nov 21, 2026
…You (CP-06)

The Tracked Competitors grid was in the order competitors were added,
without the brand, so it took reading every card to see who leads. It
now runs from the highest Visibility score to the lowest, each card with
its rank (#1, #2…), and the brand's own card, "You", in its place; a tie
puts the brand first. A brand named in fewer than 10 prompts in the
period isn't ranked: it comes after, marked Low sample (D5, D8). Without
scores the list keeps its order. Grouped by type, each group is ranked
on its own.

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

This branch was successfully deployed

1 active deployment
Preview — 44d62235 Deployed May 7, 2026 by vercel[bot]
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.

1 participant