Repository navigation
feat(content): write a page with its shopping path, the catalog's facts only (shopping path, part 4) - #1592
Conversation
…m issues (00296, ansvisor#1270 part 1) A Merchant Center account becomes a catalog source, read with the workspace's own Google sign-in through Composio (like Search Console and Analytics), so the token never reaches us. Calls go to the Merchant API v1 through Composio's proxy. - Connector merchant_center: lists the accounts the sign-in opens (plus an advanced account's sub-accounts), checks the picked one, reads every product page (1,000 a page) into the feed parsers' item shape (price from micros, first GTIN, availability and condition enums), keeps an offer listed again under another language or feed label once, and returns each product's item-level issues. syncOrders is a no-op. - 00296 catalog_item_issues: code, severity, attribute, reporting context, description per item; replaced each sync, removed with the source; members read, the server writes. - Plumbing: sign-in connectors (signIn instead of fields/connect), lib/catalog/sign-in.js (proxy request with 429/5xx waits, 'auth' when the sign-in is gone or refused), issue counts on last_counts, plain "Reconnect it in Settings › Integrations" words. - API: GET /api/catalog/accounts, POST /sources with input.account, signIns in GET /connectors, googleMerchantCenter in /integrations/config. - Tests with fixtures: paged list, items with and without issues, expired and refused sign-in, 429 wait, account picker, not set up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…account in Settings › Integrations (ansvisor#1270 part 2) - Settings › Integrations gets a "Stores and marketplaces" group: a Google Merchant Center card that connects the workspace's Google sign-in like Search Console and Analytics, then lets the active brand pick one of the accounts it opens (GET /api/catalog/accounts) and add it as a catalog source. - Product catalog names the account "Google Merchant Center · Name (id)" and its row reads "N products · M with issues · synced …"; no sign-in button for it (the sign-in is the workspace's). The card reads its sources again when an account is added above. - The Shopping page's My Products tab links to Settings › Integrations to bring in the catalog. - catalog-client: signIns in listStoreConnectors, listSignInAccounts, connectSignInAccount, not_connected; CatalogCounts.issues; IntegrationProvider 'google-merchant-center'. Words in en.json. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and keep repeated offers' issues (ansvisor#1270 review) - sign-in.js: Composio's own 401/403 and Google's 403 are not_set_up, not auth; each refusal is logged by name, status and Google's reason; only the connector's hosts (merchantapi.googleapis.com) are reached. - An offer listed again under another language or feed label is counted on its own (last_counts.repeated), its issues gathered from every listing, and the kept one chosen by a fixed rule (no DISAPPROVED issue, then feed label, then content language). - Account listing and connecting share a 30 s deadline; the sub-account walk stops on a rate limit; a catalog cut at the page limit says so. - entityIdFor moves to composio.js. Tests for paging, deadlines, limits, the proxy helper and the refusal codes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… integrations by kind, and say what the catalog is for (ansvisor#1270 review) - The picked account belongs to the brand it was picked for: switching brands clears it, an add goes to the brand clicked for, one add at once. Accounts already added are marked and can't be picked; a failed list read offers Try again; members get their own line. - Integrations' group headings are h3 headings; Webflow moves to a "Content management systems" group (IntegrationGroup). - Shopping › My Products' catalog note says what the catalog does (the editor's product-page checks), only while the brand has no source. - "1 with an issue"; a fixed platform name before /connectors is read; stores.errors.not_connected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r' into feature/merchant-center-settings
…eated offers, and note advanced accounts (ansvisor#1270 review) - settings.merchantCenter.errors.not_configured says who fixes it (the server's set-up, or the Google account's access), with Try again. - A source's line shows "N listed again, kept once" (last_counts.repeated). - With several accounts, a note says an advanced account holds no products: pick the store's own sub-account. - Every StoreError has a message (checked at typecheck); the Shopping note is _catalog-note.tsx. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… site (00350, shopping path part 1) The shopping path links a buying guide or a comparison to the category's own page, so each catalog category is matched, on every read, to one of the brand's site pages whose address reads as a category page (the editor's page-type rule: /collections/, /category/, /c/, /shop/, WooCommerce's /product-category/; never a product page or a themed collection). Best match: the last path segment is the category's name, then the title or h1 holds it, then most of its words; ties go to the more cited, then visited page. - 00350: catalog_category_pages keeps a person's decision (a page, or none) by category name; catalog_category_counts(brand) gives live products and how many are in stock (service role only). - lib/catalog/category-pages.js: categorySlug, matchCategoryPages, categoryPages(brandId), setCategoryPage (page must be on the brand's domains). - API: GET /api/catalog/categories (members), PUT and DELETE (admins and managers). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rations and let admins change it (shopping path part 1) - Category pages, under the product catalog in Stores and marketplaces: each category of the active brand with its products and how many are in stock, its page on the site, and how it was found (its address or title names the category, most of its words, set by hand). Shown once the catalog has categories. - Admins and managers change a page (it must be on the brand's site), set none, or put a hand-set one back to the automatic match; members see the table. - catalog-client: listCategoryPages, setCategoryPage, resetCategoryPage; words in settings.catalog.categories. - The API calls a person's decision 'manual' whether it's a page or none. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…(00351, shopping path part 2)
On an online shop, a buying guide, a best-of list or a comparison links the
right category page and products in stock that Merchant Center accepts. The
API picks them for the draft's topic and keeps them on the draft:
- Topic: the title's words count 3, the brief's keywords 2, its goal and
headings 1.
- Categories: with a page on the site (00350) and stock, the best first,
a second only when it scores half the first's (2 at most).
- Products: the picked categories' first, then the brand's (2,000 scored,
the best 40 read in full); offered when they have a link, a variant in
stock and Merchant Center doesn't refuse that variant; the cheapest such
variant's price, and its non-refusing issues (e.g. missing GTIN). How
many by page type: best-of 8, buying guide 5, comparison and
alternatives 4, guide 4, blog post 3. The best left out are kept with
why (sold out, refused, no link).
- The person's choices survive a rebuild: locked and added products stay
(counted in the page's number), removed ones never come back.
- 00351 content_drafts.shopping_path jsonb (64 KB at most); members edit
it like the brief.
- POST /api/content-drafts/:draftId/shopping-path { brandId }: { path },
or { path: null, reason } ('not_a_shop', 'page_type', 'no_catalog').
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s Brief tab (shopping path part 3) Brief › Shopping path, above the brief, for a page type that links products (best-of, buying guide, comparison, alternatives, guide, blog post) on an e-commerce brand: - Pick from the catalog the first time (POST /:draftId/shopping-path), Pick again after; why a draft takes none (not a shop, page type, no catalog). - The category page with where it goes (in the intro and at the end). - Each product with its price (sale price first, en-US in its currency), In stock or Low stock, its Merchant Center issues, and its place by page type (Top picks #n, Compared #n, linked in the text). - Lock (kept when picked again or rewritten), Remove (saved at once), Swap (removed, then picked again for the next best), Add product (search the catalog's names, then picked again with it kept). - The best products left out, with why (sold out, Merchant Center refuses it, no page to link). - actions/shopping-path.ts: read and save through RLS like the brief, build through the API, search the catalog. lib/content/shopping-path.ts: the path's schema, which pages take one, places, changes. Words in contentEditor.editor.shopping; shopping_path in types/supabase.ts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts only (shopping path part 4) The Content Agent now writes with the draft's shopping path: - A new page: the writer is told the category page (name it in the opening, point to it again at the end) and the products in order with the catalog's price and stock only, never another spec (a placeholder instead). It writes text, so the names it wrote are linked afterwards (shopping-links.js linkShoppingPath): each target the first time a paragraph or a list item names it, never in a heading or inside a link; products first, longest names first; a category's last word singular or plural too. - A page it changes (rewrite from brief, suggestions, rule fixes): the path's pages join the pages it may link to, first in the prompt whatever the rules, and in the allow list (anything else is still unwrapped). - The path's names and prices are given to the number and people guards, so the catalog's price isn't turned into a placeholder. - content-links.js: linkTargetsPrompt and linkAllowList read targets.shopping; startDraftWriting and fixDraftRules read shopping_path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s own rule (shopping path part 1 review) - A malformed % in a page address no longer breaks the read. - Pages and categories are prepared once, with a word index; site_pages isn't read when nothing can match. - GET uses the general limiter; PUT/DELETE get their own bucket. - The category-page rule is the editor's (page-types.ts), checked on both sides by one fixture list; /blog/category/ and pages marked first (best-of, size guides, -vs-, policies) aren't category pages. - Parent words count; a one-word category matches by address only. - Turkish and German letters fold (lib/letters.js, shared with Webflow). - The table is read again when sources change; editing resets per brand. - catalog_category_counts counts the web's four in-stock values. - PUT refuses a category the catalog doesn't have; messages fit the routes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…talog row, with one stock rule (shopping path part 2 review) - Locked and added products are read by id from the brand's own catalog, always kept; a removed or unknown one is left out as 'gone'. - Every read is chunked and paged past PostgREST's 1,000-row cap. - The route has its own bucket (shoppingPathLimiter); descriptions are cut to 400 characters once read. - More stop words and years, letters folded as category pages do, and 'no_match' when nothing fits. - A refusal counts only for free listings or an empty context. - One stock list (catalog/stock.js), the same as feed-match.ts and 00350. - The saved path is read through Zod; a bad one is taken as none and logged. Writes are capped to 64 KB and conditional on builtAt/savedAt (409 'changed'). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The table was 640 px wide in a 417 px card at 1024 px. The Change buttons sat out of sight, and the header's screen-reader label, outside the scroll box, scrolled the whole page sideways. - How a page was found is now a line under it, so four columns fit. - While a category is being changed, its form takes the button's cell as well. - The scroll box contains its label (`relative`). - Addresses wrap only where they must ([overflow-wrap:anywhere]). Co-Authored-By: Claude Opus 5.5 <[email protected]>
… new path shape (shopping path part 3 review) - The schema takes the API's shape: 'gone' and a missing title for a product left out, 'no_match', savedAt, availability in lowercase with underscores, and the same caps as the server. A reason it doesn't know reads as a general line instead of failing. - A change is saved before the path is picked again, so a failed pick (429, 502) doesn't lose it. - A save writes only locked, removed and added, and only over the path that was read (builtAt and savedAt). Otherwise it answers 'changed' and the tab reads the path again. A build's 409 'changed' and 429 have their own lines. - An unreadable saved path, 'no_match' or an unknown reason offers "Pick from the catalog". - Links must be http(s); others show without a link. - The search has its own error; the Lock button has a fixed name with aria-pressed. - Removed: the unused fromCatalog string. - Rows are keyed by their place and name; the category path wraps with [overflow-wrap:anywhere]. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the catalog and the brand's site give them (shopping path part 4 review) - shoppingPathFor reads the path once per run through readShoppingPath. A bad shape counts as no path and is logged; the run goes on. - Prices pass in their usual forms ($189, 189 USD, ₺1.299,00), with the sign matching the currency; any other price becomes a placeholder. - Stock is read fresh from catalog_variants at write time and named through stock.js. Unknown stock says nothing. - Links: https and the brand's own domains only (brandSite, shared with category pages). - Product names match case-sensitively and category names don't. Letters are folded, and singulars come from category pages. - The fix path guards prices and names too. - A name or address is used once. A product name's numbers are free only where the name stands. - The prompt takes as many products as the page type links, 40 at most, locked and added ones kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
left a comment
There was a problem hiding this comment.
Needs changes: one fix before merge, so the prices the agent writes are the catalog's current ones. The rest are follow-ups.
What I checked:
- Own change.
origin/pr/1591..origin/pr/1592, server only: 4c175d7, 96e6194, and the merge 369d0bf of #1591's head. A re-merge of its parents gives its tree, so it hides nothing. - What the writer is told.
- A new page's prompt names the category page by its own name. It lists the products in order, one line each, with "price CODE, stock".
- Whitespace in names is collapsed, so a name can't add a line to the prompt.
- The count is
PRODUCTS_FORfor the path's page type, with locked and added products always kept, and 40 at most. - Pages off the brand's site, or not https, are dropped first. The site is
brand_domains, or the catalog's product hosts for a brand with none stored. - Suggestions, rewrites and Fix get the same pages as link targets (name and address), first in the list whatever the rules.
- The guards.
- The price (the sale price first) joins the known numbers in four spellings, with the sign that goes with its currency.
- A product's own numbers ("Trail 450") are known only where its whole name stands.
- I tried them on their own:
$189and189 USDfor a $189 product pass;€189and$199are replaced for it, and so are$1,299for a TRY product and "weighs 450 grams";₺1.299,00passes for a TRY product.
- What still passes is the number guard's general reach, as before this PR:
- a known price passes anywhere on the page with its sign, so "another boot costs $189" stays;
- a code or a sign after the number isn't read, so "189 EUR" for a USD product stays.
- A competitor's product name isn't checked; no guard reads product names, before or after this PR. Its price is replaced unless it equals a catalog price, and it can't be linked. A new page is plain text, linked afterwards to the path's pages only. Suggestions and fixes keep only allow-listed links.
- Links.
- https only, on the brand's site, tracking dropped, with each name and each address linked once.
- Never in a heading or inside a link. The linker escapes the text and the address.
- Non-ASCII text and entities come through cheerio's re-serialization as they were (checked on a Turkish page).
- Old drafts. With no path,
shoppingPathForreturns before it reads anything. The prompt, the guards, the links and the page stay as they are. - AI budget. No new model call. The longer prompt (40 product lines at most) goes under the same hold and is charged by its real tokens.
- Tests.
- With #1591's sources under this PR's tests, 16 fail:
shopping-links.test.js, and the writer's and Fix's shopping path cases. - On the head they pass. Three existing timing tests ("…quickly") each failed once on a loaded machine. They pass when run alone, and one failed the same way with #1591's sources. CI passes.
- With #1591's sources under this PR's tests, 16 fail:
- Merge.
- Deploy.
- Nothing changes until the API is deployed.
- The writer and Fix now read
shopping_pathwith the draft. So 00351 must be on prod before this API goes out; without the column, every Run Agent and Fix fails reading the draft.
Before merge:
- Read the price with the stock (
shopping-links.js:192-218, used byofferLine:79-84andpriceSpellings:87-96).- Stock is read again at write time, but the price is still the one saved when the products were picked. A price change or an ended sale since then is written as the catalog's price, and the guard lets it through.
- With the new stock, the line can also mix two variants. "189.00 USD, in stock" can be the price of a variant that has since sold out and the stock of a dearer one.
- A product with no live variant left (gone from the catalog) is still written and linked at its old price, with nothing said about stock.
- Fix:
- Select
price, sale_price, currencyin the samecatalog_variantsread. - Take the price and the stock from one variant: the best stock, then the lowest price at that stock.
- With no live variant, give no price, or leave the product out.
- On a failed read, keep the saved values, as now.
- Select
- Test: a variant's price changes after the pick. The prompt and the guard use the new price, and the old one becomes a placeholder.
Follow-ups:
2. Write only with a path the Brief tab shows (shopping-links.js:227-252).
- The tab shows the path only on an e-commerce brand, for a page type in
PRODUCTS_FOR. The agent uses a stored path whatever the draft's page type is now. A buying guide switched to a product page is still written to "recommend or compare" its products, and the person can't see or remove them there. pathProducts(:141-149) also counts by the path's page type, not the draft's.- Fix: pass
brandin (both callers readsite_type,industryandshopping_mode_enabled), and return null unlesssiteTypeOf(brand) === 'ecommerce'andPRODUCTS_FORhasdraft.page_type. Count the products bydraft.page_type. - See also #1591's first follow-up: a pick that finds nothing leaves the old path stored.
- Bound the work on a long paragraph (
linkShoppingPath,:104-125and:334-376).readablechecksout.endsWith(' ')right afterout += read, so each space copies the text read so far. Its time grows with the square of the paragraph's length.- It runs again for every target and every text node, and
textNodes()walks the page again per target. - Fix: keep whether the last character was a space in a variable (or build
outfrom an array), computereadableonce per text node and fold mode, and walk the nodes once, linking each target where it first matches.
- Bound the names read from a stored path (
:156-175).- The build cuts titles to 200 characters, but
readShoppingPathdoesn't bound a name's length. A stored name of tens of kilobytes goes into the prompt whole. Over about 35 KB it makes the name patterns (withNamedNumbers,linkShoppingPath) too large to compile, and the run fails. - Fix: in
shoppingPathFor, leave out a category or product whose name is overTITLE_CHARS(200), as the build never writes one.
- The build cuts titles to 200 characters, but
- Give the guards the category's name as the agent writes it (
shoppingGiven,:290-299).- The prompt names the category by its own name (
leafName). The guards get the full path ("Electronics > 4K TVs"), so its numbers are known only where the full path is written. "Browse our 4K TVs" becomes "Browse our [figure, source] TVs" unless the title or brief has "4K", and the name can't be linked. - Fix: add
t.titletonamesfor a category, next tot.item.name.
- The prompt names the category by its own name (
- The category page is linked once. The prompt asks for it in the opening and again at the end, and the test plan expects a link at the end. The linker links each target only the first time (
:372), so the closing mention stays plain text. Either link a category's last mention too, or make the test plan say it's linked in the opening.
|
Taking the before-merge item over to save a round trip: I'll read the price with the stock from one live variant, and bound the linking and the stored names (follow-ups 3 and 4). Please don't push to the branch meanwhile; I'll note here when it's done. |
… its stock The price is read with the stock, both from one live variant (the best stock, then the lowest price at it), so the line never mixes two variants or keeps an ended sale. A product gone from the catalog gets no price or stock. A stored name longer than the build keeps is left out, and the linking reads a long paragraph in time near its length.
|
Done in the latest commit on the branch: the price is read with the stock from one live variant (the best stock, then the lowest price at it), and a product gone from the catalog gets no price or stock. Stored names past TITLE_CHARS are left out (follow-up 4) and the linking's text read is linear (part of follow-up 3). New tests fail on the previous head. Follow-ups 2, 5 and 6 are still yours. |
Summary
E-commerce Shopping path, part 4 of 7: the Content Agent writes with it. When a draft has a shopping path (parts 2 and 3), the agent's new page links its category page and products, and states their prices and stock only as the catalog gives them.
Stacked on #1591 (part 3), which is stacked on #1588, #1587, #1583 and #1582. This PR's own change is its commits after #1591's: 4c175d7 (the agent) and 96e6194 (the pre-push review's fixes). Server only.
lib/shopping-links.js:shoppingPathFor(draft): the path as a run reads it, once per run.readShoppingPath. A bad shape counts as no path, and the run goes on (logged).brand_domains, or the catalog's product links for a brand with none stored (brandSite, shared with category pages).catalog_variantsat write time and named throughcatalog/stock.js: in stock, low stock, available to pre-order, on backorder, out of stock. Unknown stock says nothing. A failed read falls back to the saved stock and is logged.shoppingPrompt) gives the category page and where it goes, then each product with its price as given and its stock. It takes as many products as the page type links (PRODUCTS_FOR), 40 at most. Locked and added products are always kept and counted.shoppingGiven): the catalog's prices and the product names count as given facts.189,$189.00,189 USD,US$189,₺1.299,00), with the sign matching the currency.€189for a USD product,$199) becomes a[figure, source]placeholder.withNamedNumbersincontent-sources.js).content-agent.js) keeps the same prices and names.linkShoppingPath): the names the agent wrote are linked to their pages after writing.İ/I/ı) and plurals made singular as category pages do ("Glasses" → "glass").Related issue
Part of the e-commerce Shopping path plan (Drive › E-commerce › ECOM-shopping-journey-plan.md §6), part 4 of 7. Builds on #1270 (#1582, #1583), #1587, #1588 and #1591.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/shopping-links.test.js src/lib/content-writer.test.js src/lib/content-agent.test.js src/lib/content-sources.test.js src/lib/catalogThere is no browser check here: the agent needs an AI key. The behaviour is covered by the tests above.
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) — no web change of its own (the web is feat(content): show and change a draft's shopping path in the editor's Brief tab (shopping path, part 3) #1591's, checked there)yarn typecheckpasses (run fromweb/) — as aboveyarn format:checkpasses (run fromweb/) — as aboveAlso run on this head (with #1591 merged in), in
server/:npm run format,npm run lintandnpm test(3,115 tests pass).The pre-push review's nine findings are folded into 96e6194, with tests:
The fixer broke 18 behaviours one at a time to check that the tests catch them.
Left for its own PR: the MCP link targets (
web/src/lib/content/link-targets.ts) don't know the shopping path yet.🤖 Generated with Claude Code