Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(content-editor): count the page type's own rules and a product page's shipping and returns in Quality (CE-052, part b) (#1494)
Cihanea0d7af1a823
diff --git a/server/src/lib/content-handoff.js b/server/src/lib/content-handoff.jsindex 009712239..042f33bb4 100644--- a/server/src/lib/content-handoff.js+++ b/server/src/lib/content-handoff.js@@ -24,6 +24,8 @@ export const HANDOFF_CHECKS = {'readability:headingSpacing':'A heading every 200–300 words: add an H2 or H3 where a section runs long, named for what it covers','readability:passiveJargon': 'Active voice and plain words: rewrite passive sentences and jargon',+ 'readability:typeRules':+ "The page type's own rules named here, each with its aim and how the page reads now (a specs table, a side-by-side table, an intro, a buying FAQ, how-to steps): meet each aim from the page and your data only; a table of facts (specs, sizes) gets only the facts given, a placeholder in each cell you can't fill, never one made up; an answer the page and your data don't give (fit, sizes, shipping, returns, prices) is a placeholder too, never one made up",'trust:claimsSourced':'Every figure or claim has a source in its paragraph: link one from your data; where you have none, write the figure as a placeholder or soften the claim, never make one up','trust:brandFacts':diff --git a/server/src/lib/content-handoff.test.js b/server/src/lib/content-handoff.test.jsindex 890245072..a288169b1 100644--- a/server/src/lib/content-handoff.test.js+++ b/server/src/lib/content-handoff.test.js@@ -25,6 +25,16 @@ describe('handOffInput', () => {// A to-do (the person's), or a key it doesn't know: refused.expect(handOffInput.safeParse({ items: [{ key: 'eeat:experience' }] }).success).toBe(false);expect(handOffInput.safeParse({ items: [] }).success).toBe(false);+ // Phase 3 (CE-052): the page type's own rules, as the Rules tab reads them.+ expect(+ handOffInput.safeParse({ items: [{ key: 'readability:typeRules', detail: 'Specs table' }] })+ .success,+ ).toBe(true);+ expect(HANDOFF_CHECKS['readability:typeRules']).toMatch(/never one made up/);+ // An answer too: fit, sizes, shipping, returns and prices only from the page and the data.+ expect(HANDOFF_CHECKS['readability:typeRules']).toMatch(+ /an answer the page and your data don't give \(fit, sizes, shipping, returns, prices\) is a placeholder too/,+ );expect(handOffInput.safeParse({ items: [{ key: 'readability:longSentences' }], origin: 'cron' }).success,diff --git a/web/messages/en.json b/web/messages/en.jsonindex eed6844c2..cde9311cc 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -4706,10 +4706,10 @@"change": "Change","changeLabel": "Change the page type","article": "an author with experience, sourced claims, short sentences and the answer first.",- "product": "no author (your brand's), your own product photos, proof for claims, prices that match, short plain copy.",- "category": "your own product images, your brand's information on its site, prices and claims that match.",- "feature": "your own screenshots and data, sourced metrics, a price that matches, scannable sections.",- "comparison": "an author who says how the picks were made, balance and a disclosure, the summary first."+ "product": "no author (your brand's), your own product photos, proof for claims, prices that match, shipping and returns, a specs table and short plain copy.",+ "category": "your own product images, your brand's information on its site, prices and claims that match, an intro and a buying FAQ.",+ "feature": "your own screenshots and data, sourced metrics, a price that matches, a comparison table, proof per section and use case steps in scannable sections.",+ "comparison": "an author who says how the picks were made, balance and a disclosure, a side-by-side table, the summary first."},"tooShort": "Write a few paragraphs: Readability is read from the page as you write.","tooShortShort": "Too short yet",@@ -4755,6 +4755,12 @@"given": "It's in Your input, but the page doesn't quote it word for word yet","done": "The page quotes an expert word for word"},+ "shippingReturns": {+ "title": "Say how shipping and returns work",+ "next": "say how shipping and returns work",+ "detail": "The delivery time and cost and the return window, in the page or as links to your shipping and returns pages. Only you know them: the agent leaves them to you",+ "done": "The page says how shipping and returns work"+ },"brandFacts": {"title": "{count, plural, =0 {Review your brand facts} one {Approve # brand fact} other {Approve # brand facts}}","next": "approve {count, plural, one {# brand fact} other {# brand facts}}",@@ -4986,6 +4992,10 @@"passiveJargon": {"line": "{passive, plural, one {# passive sentence} other {# passive sentences}} · {jargon, plural, one {# jargon word} other {# jargon words}}","detail": "Say who does what, in plain words."+ },+ "typeRules": {+ "line": "{count, plural, one {# page type rule not met} other {# page type rules not met}}: {names}",+ "detail": "{rules}. This page type's own rules, as the Rules tab reads them: meet them there, or Run Agent in Rules."}}},@@ -5095,6 +5105,7 @@"addKeywords": "Add keywords","notHowTo": "Not a how-to","englishOnly": "English only",+ "noSizes": "No sizes","numberCheck": "Number check"},"mineName": "My rules · {type}",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsxindex c7b9bdf03..7935937a3 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx@@ -108,6 +108,7 @@ import { inputsGiven, inputsUsed } from '@/lib/content/draft-inputs';import {eeat,linksToCheck,+ shippingOnPage,squeeze,trust,trustBlocks,@@ -123,7 +124,7 @@ import {weighedTrust,} from '@/lib/content/quality-profiles';import { proofKey, qualityTodos } from '@/lib/content/quality-todos';-import { isByline, readability, sentencesOf } from '@/lib/content/readability';+import { isByline, readability, sentencesOf, withTypeRules } from '@/lib/content/readability';import { brandFactsPath, factMismatches } from '@/lib/content/brand-facts';import {MAX_PROOF_TODOS,@@ -148,6 +149,8 @@ import {openRulesForAgent,lengthBand,rewriteAdvice,+ type ActiveRule,+ type RuleStatus,} from '@/lib/content/rules';import { aiUsageTone } from '@/lib/billing/ai-usage';import { saveBlob } from '@/lib/download';@@ -373,6 +376,13 @@ export function DraftEditor({// Whether the side panel's brief is rebuilding, as it last said.const briefNow = useRef(false);const tRules = useTranslations('contentEditor.editor.rules');+ /** A rule's aim and how the page reads now, as the agent is told them (Fix open rules, Hand off). */+ const aimAndNow = (rule: ActiveRule, status: RuleStatus) => [+ rule.current+ ? `${tRules('agent.aim')}: ${rule.current}${rule.unit ? ` ${tRules(`units.${rule.unit}`)}` : ''}`+ : null,+ `${tRules('agent.now')}: ${ruleStatusDetail(tStatus, status)}`,+ ];const tStatus = useTranslations('contentEditor.editor.rules.status');// History keeps the page before the first suggestion accepted here.const agentBeforeKept = useRef(false);@@ -753,15 +763,44 @@ export function DraftEditor({// page's type (an article's before, and for most types).const profile = profileFor(pageType);const weights = PROFILE_WEIGHTS[profile];+ // A product page's shipping and returns (CE-052): Trust's check, and a+ // to-do that needs no Trust read.+ const shippingRead = useMemo(+ () => (qualityOn && profile === 'product' ? shippingOnPage(pageHtml, language) : null),+ [qualityOn, profile, pageHtml, language],+ );+ // The page type's own rules (the Rules tab's, read from the page): one+ // Readability check on the types that weigh it; not ones read by AI or+ // the product feed, nor ones turned off there.+ const typeRules = useMemo(+ () =>+ rules.rules.flatMap(({ rule, status }) =>+ rule.group === 'type' && rule.check === 'page' && rule.on && status.state !== 'info'+ ? [+ {+ name: tRules(`names.${rule.key}`),+ met: status.state === 'ok',+ detail: aimAndNow(rule, status).filter(Boolean).join(' · '),+ },+ ]+ : [],+ ),+ // aimAndNow reads only tRules and tStatus.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ [rules.rules, tRules, tStatus],+ );const readable = useMemo(() =>qualityOn? weighed(- readability(pageHtml, language, aiChecks?.answerFirst ?? null),+ withTypeRules(+ readability(pageHtml, language, aiChecks?.answerFirst ?? null),+ typeRules,+ ),weights.readability,): null,- [qualityOn, pageHtml, language, aiChecks, weights],+ [qualityOn, pageHtml, language, aiChecks, weights, typeRules],);// A proof to-do asked for this session stays, checked once it has a link.const [hadProofs, setHadProofs] = useState<ReadonlySet<string>>(() => new Set());@@ -902,6 +941,8 @@ export function DraftEditor({brandFacts: factCheck,proofs: proofAsks,page: aiChecks,+ // A product page's shipping and returns (CE-052).+ shipping: shippingRead,now: Date.now(),}),weights.trust,@@ -909,6 +950,7 @@ export function DraftEditor({: null,[weights,+ shippingRead,qualityOn,pageBlocks,linkChecks,@@ -1044,6 +1086,7 @@ export function DraftEditor({// Once the authors are read: who the reviewer is, and whether any can be.reviewer: regulated && authorsRead ? { topic: regulated, picked: !!pageReviewer } : null,confirmed: authorConfirmed,+ shipping: shippingRead,off: checksOff(profile),}): [];@@ -1765,10 +1808,7 @@ export function DraftEditor({key: rule.key,name: tRules(`names.${rule.key}`),detail: [- rule.current- ? `${tRules('agent.aim')}: ${rule.current}${rule.unit ? ` ${tRules(`units.${rule.unit}`)}` : ''}`- : null,- `${tRules('agent.now')}: ${ruleStatusDetail(tStatus, status)}`,+ ...aimAndNow(rule, status),rule.key === 'aiTraces'? `${tRules('agent.phrases')}: ${aiTracesFound(pageText).join(', ')}`: null,diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.test.tsxindex 2c2ccc307..ab88fc3c3 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.test.tsx@@ -145,7 +145,7 @@ describe('QualityTab', () => {p.textContent?.startsWith('Checks and weights for'),)!;expect(line.textContent).toBe(- "Checks and weights for Product page (detected): no author (your brand's), your own product photos, proof for claims, prices that match, short plain copy. Change",+ "Checks and weights for Product page (detected): no author (your brand's), your own product photos, proof for claims, prices that match, shipping and returns, a specs table and short plain copy. Change",);await act(async () => line.querySelector('button')!.click());expect(onChangeType).toHaveBeenCalled();@@ -162,6 +162,31 @@ describe('QualityTab', () => {expect(container.textContent).not.toContain('Checks and weights for');});+ it('names the page type’s rules not met yet, and a product page’s shipping to-do (CE-052)', async () => {+ const typed: Readability = {+ ...result,+ checks: [+ ...result.checks,+ {+ id: 'typeRules',+ points: 0,+ max: 10,+ value: 1,+ count: 1,+ rules: [{ name: 'Specs table', detail: 'Now: missing' }],+ },+ ],+ };+ await render({+ ...read(typed),+ todos: [{ id: 'shippingReturns', done: false, gain: 4, score: 'trust', action: null }],+ });+ expect(container.textContent).toContain('1 page type rule not met: Specs table');+ // Each with how the page reads now: what Hand off sends the agent too.+ expect(container.textContent).toContain('Specs table (Now: missing). This page type');+ expect(container.textContent).toContain('Say how shipping and returns work');+ });+it('shows the three scores with their bands, labelled an Ansvisor estimate', async () => {await render(result);const scores = container.querySelector('[aria-label="Quality scores"]')!;diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsxindex 46153edb3..8ba05dd1e 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx@@ -480,6 +480,14 @@ export function useTodoCopy() {: t('visualProof.detail.add'),};}+ // A product page's shipping and returns (CE-052): only the person knows them.+ if (todo.id === 'shippingReturns') {+ return {+ title: t('shippingReturns.title'),+ next: t('shippingReturns.next'),+ detail: todo.done ? t('shippingReturns.done') : t('shippingReturns.detail'),+ };+ }// How the page was made (CE-050): the page read finds it or not.if (todo.id === 'whoHowWhy') {return {@@ -951,6 +959,11 @@ function line(t: T, check: ReadabilityCheck): string {return t('checks.headingSpacing.line', { count: check.count, words: SECTION_WORDS });case 'passiveJargon':return t('checks.passiveJargon.line', { passive: check.count, jargon: check.value });+ case 'typeRules':+ return t('checks.typeRules.line', {+ count: check.count,+ names: (check.rules ?? []).map((r) => r.name).join(', '),+ });}}@@ -968,6 +981,14 @@ function detail(t: T, check: ReadabilityCheck): string {? t('checks.readingLevel.detail', { target: check.target ?? 60 }): t('checks.readingLevel.detailLength');}+ // Each rule with its aim and how the page reads now: what Hand off sends the agent too.+ if (check.id === 'typeRules') {+ return t('checks.typeRules.detail', {+ rules: (check.rules ?? [])+ .map((r) => (r.detail ? `${r.name} (${r.detail})` : r.name))+ .join('; '),+ });+ }return t(`checks.${check.id}.detail`);}diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsxindex 47c7b9aea..ee0582d03 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx@@ -2573,6 +2573,34 @@ describe('the side panel', () => {expect(todos()).toContain('Add an author for the page');});+ it('asks a product page for its type rules and its shipping and returns in phase 3 (CE-052)', async () => {+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '3';+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });+ getContentAuthors.mockResolvedValue({+ authors: [],+ brands: [{ id: 'b1', name: 'Acme' }],+ me: { id: 'u1', role: 'admin' },+ });+ getContentDraft.mockResolvedValue({+ ...readable,+ pageType: 'product_page',+ siteType: 'ecommerce',+ });+ window.innerWidth = 1440;+ await renderPage();+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));+ const chip = [...container.querySelectorAll<HTMLButtonElement>('header button')].find((b) =>+ b.textContent?.startsWith('Quality'),+ )!;+ await act(async () => chip.click());+ const text = panel()!.textContent!;+ expect(text).toContain('Checks and weights for Product page');+ // The Rules tab's specs table, read from the page; no sizes, so no fit questions.+ expect(text).toMatch(/1 page type rule not met: Specs table/);+ expect(text).toContain('Say how shipping and returns work');+ expect(text).not.toContain('Add an author for the page');+ });+it('shows nothing of Quality until its first phase is live', async () => {getContentDraft.mockResolvedValue(readable);window.innerWidth = 1440;diff --git a/web/src/lib/actions/content-drafts.ts b/web/src/lib/actions/content-drafts.tsindex 265cc5c1b..85b38da56 100644--- a/web/src/lib/actions/content-drafts.ts+++ b/web/src/lib/actions/content-drafts.ts@@ -88,6 +88,7 @@ import {type VersionOrigin,} from '@/lib/content/history';import { RUN_STALE_MS } from '@/lib/content/agent-runs';+import { HANDOFF_KEYS } from '@/lib/content/hand-off';import type { AgentWriteRequest } from '@/lib/content/agent-write';import {actionPages,@@ -2302,7 +2303,7 @@ export async function handOffDraft(},body: JSON.stringify({brandId,- items: request.items.slice(0, 15).map((item) => ({+ items: request.items.slice(0, HANDOFF_KEYS.size).map((item) => ({key: item.key.slice(0, 60),detail: item.detail.slice(0, 500),})),diff --git a/web/src/lib/content/hand-off.test.ts b/web/src/lib/content/hand-off.test.tsindex 3df107ace..262c23b9f 100644--- a/web/src/lib/content/hand-off.test.ts+++ b/web/src/lib/content/hand-off.test.ts@@ -78,7 +78,7 @@ describe('handOffItems', () => {);const block = server.slice(server.indexOf('HANDOFF_CHECKS = {'), server.indexOf('};'));const keys = [...block.matchAll(/^\s*'([a-z]+:[A-Za-z]+)':/gm)].map((m) => m[1]);- expect(keys).toHaveLength(15);+ expect(keys).toHaveLength(16);expect([...HANDOFF_KEYS].sort()).toEqual(keys.sort());});});diff --git a/web/src/lib/content/hand-off.ts b/web/src/lib/content/hand-off.tsindex e43db50d3..b6a4dab81 100644--- a/web/src/lib/content/hand-off.ts+++ b/web/src/lib/content/hand-off.ts@@ -16,6 +16,8 @@ export const HANDOFF_KEYS: ReadonlySet<string> = new Set(['readability:shortParagraphs','readability:headingSpacing','readability:passiveJargon',+ // Phase 3 (CE-052): the page type's own rules, as the Rules tab reads them.+ 'readability:typeRules','trust:claimsSourced','trust:brandFacts','trust:freshSources',diff --git a/web/src/lib/content/quality-checks.test.ts b/web/src/lib/content/quality-checks.test.tsindex 2fdcd21b1..b727f87d4 100644--- a/web/src/lib/content/quality-checks.test.ts+++ b/web/src/lib/content/quality-checks.test.ts@@ -8,6 +8,7 @@ import {authorProfile,eeat,linksToCheck,+ shippingOnPage,scoreGain,sentenceGain,trust,@@ -694,3 +695,110 @@ describe('the page read’s AI checks (Phase 2, CE-050)', () => {).toBeNull();});});++describe('shippingOnPage (Phase 3, CE-052)', () => {+ const read = (html: string) => shippingOnPage(html);++ it('reads how shipping and returns work in a policy’s terms, headings and links too', () => {+ expect(read('<p>Free shipping in 2 days. Free returns within 30 days.</p>')).toEqual({+ shipping: true,+ returns: true,+ });+ expect(+ read(+ '<h2>Returns</h2><p>Ships within 24 hours.</p><p>30-day returns, no questions asked.</p>',+ ),+ ).toEqual({+ shipping: true,+ returns: true,+ });+ expect(+ read(+ '<p>See <a href="/policies/shipping_policy">delivery</a> and <a href="/pages/returns-and-refunds">this</a>.</p>',+ ),+ ).toEqual({ shipping: true, returns: true });+ expect(+ read('<p>Details: <a href="#versandkosten">Versand</a>, <a href="/reembolso">aquí</a>.</p>'),+ ).toEqual({+ shipping: true,+ returns: true,+ });+ // Turkish, capital İ at a sentence's start too.+ expect(read('<p>Kargo ücretsiz. İade koşulları: 14 gün.</p>')).toEqual({+ shipping: true,+ returns: true,+ });+ });++ it('reads the common ways shops state their terms (#1494 review)', () => {+ const shipping = [+ '<h3>Delivery & Returns</h3><p>We send every order with tracking.</p>',+ '<p>Standard delivery 3–5 working days.</p>',+ '<p>Free UK delivery on orders over £50.</p>',+ '<p>Delivery: 2–4 working days.</p>',+ '<p>Expédition sous 24h.</p>',+ '<p>Entrega en 24/48 horas.</p>',+ '<p>Versand innerhalb von 2 Tagen.</p>',+ '<p>Siparişiniz 2 iş gününde teslim edilir.</p>',+ '<h2>Shipping</h2><p>Orders leave our warehouse daily.</p>',+ ];+ for (const html of shipping) expect(read(html)?.shipping).toBe(true);+ const returns = [+ '<p>Returns are accepted within 30 days.</p>',+ '<h2>Returns & Exchanges</h2><p>Send it back unused.</p>',+ '<p>Retours acceptés, satisfait ou remboursé.</p>',+ '<p>Reembolso en 14 días.</p>',+ '<p>Kostenlose Retoure und Umtausch.</p>',+ '<p>Ücretsiz değişim hakkı.</p>',+ ];+ for (const html of returns) expect(read(html)?.returns).toBe(true);+ });++ it('reads no policy in everyday words', () => {+ for (const html of [+ '<p>Ships with a USB-C cable. In return, you get a two-year warranty.</p>',+ '<p>A strong return on investment, served from a content delivery network.</p>',+ '<p>Press Return to save. Trade it on any stock exchange.</p>',+ '<p>A sturdy daypack for wet hikes.</p>',+ // A spec, a product's link, a product named for the word.+ '<table><tr><td>Shipping weight</td><td>1.2 kg</td></tr></table>',+ '<p>See our <a href="/collections/delivery-bags">delivery bags</a>.</p>',+ '<p>Kargo pantolon, yüzde 100 pamuk.</p>',+ // A policy's heading with nothing under it.+ '<h2>Shipping</h2><h2>Materials</h2><p>Recycled nylon.</p>',+ ]) {+ expect(read(html)).toEqual({ shipping: false, returns: false });+ }+ });++ it('reads a page in a language its words aren’t written for by its links alone', () => {+ expect(shippingOnPage('<p>Spedizione gratuita in 24 ore.</p>', 'it')).toBeNull();+ expect(+ shippingOnPage('<p>Vedi <a href="/policies/shipping-policy">spedizione</a>.</p>', 'it'),+ ).toEqual({ shipping: true, returns: false });+ });+});++describe('trust: a product page’s shipping and returns (Phase 3, CE-052)', () => {+ const NOW = Date.parse('2026-10-25');++ it('counts half for one of the two, and is left out where not read', () => {+ const run = (shipping: { shipping: boolean; returns: boolean } | null) =>+ trust({+ blocks: trustBlocks('<p>Win rates rose 42% last year.</p>'),+ links: new Map(),+ brandDomains: ['acme.com'],+ shipping,+ now: NOW,+ });+ expect(+ run({ shipping: true, returns: false }).checks.find((c) => c.id === 'shippingReturns'),+ ).toEqual({+ id: 'shippingReturns',+ points: 5,+ max: 10,+ });+ expect(run(null).checks.some((c) => c.id === 'shippingReturns')).toBe(false);+ expect(run(null).shipping).toBeNull();+ });+});diff --git a/web/src/lib/content/quality-checks.ts b/web/src/lib/content/quality-checks.tsindex 4c337d5de..90cc9c4a8 100644--- a/web/src/lib/content/quality-checks.ts+++ b/web/src/lib/content/quality-checks.ts@@ -1,7 +1,7 @@import { classifyDomain, normalizeDomain } from '@/lib/citations/classify';import type { ContentAuthor } from './authors';import { cleanHref } from './html-allowlist';-import { ownText, sentencesOf } from './readability';+import { languageCode, ownText, sentencesOf } from './readability';import type { FactMismatch } from './brand-facts';import type { ClaimBlock } from './claims';import { askableSite, sourceClass, type AiSourceClass, type SourceClass } from './source-class';@@ -65,9 +65,113 @@ export const TRUST_WEIGHTS = {disclosure: 5,noBrokenLinks: 3,siteTrust: 5,+ // Phase 3 (CE-052): a product page's shipping and returns; weighed there.+ shippingReturns: 0,} as const;export type TrustCheckId = keyof typeof TRUST_WEIGHTS;+/** The shipping and returns check's points before a page type weighs it. */+const SHIPPING_POINTS = 10;+/**+ * Words that say how a product ships, in a policy's terms: "free shipping",+ * "shipping takes 2 days", "Free UK delivery on orders over £50", "Standard+ * delivery 3–5 working days", "Expédition sous 24h", "Entrega en 24/48+ * horas", "ücretsiz kargo", "2 iş gününde teslim". Not a bare "shipping"+ * ("Shipping weight: 1.2 kg"), "ships with a cable", or a product named+ * for it ("kargo pantolon").+ */+const SHIPPING_WORDS = new RegExp(+ String.raw`(?<!\p{L})(?:${[+ String.raw`(?:free|fast|standard|express|next[- ]day|same[- ]day|flat[- ]rate|worldwide|international)\s+(?:\p{L}+\s+)?(?:shipping|delivery)`,+ String.raw`shipping\s+(?:is|costs?|fees?|times?|takes|in|within|on|to|from|policy|rates?|&|and|information|details|options)`,+ String.raw`ships?\s+(?:in|within|free|worldwide|from|next|same|today|by)`,+ String.raw`delivery\s*:?\s*(?:\p{L}+\s+){0,3}(?:\d+(?:\s*[–—-]\s*\d+)?|one|two|three)\s*(?:working\s+|business\s+)?(?:days?|hours?|h|weeks?)(?!\p{L})`,+ String.raw`delivery\s+(?:times?|in|within|costs?|fees?|is\s+free|charges?)`,+ String.raw`delivered\s+(?:in|within|free|by)`,+ String.raw`dispatch(?:ed|es)?\s+(?:in|within|the\s+same)`,+ String.raw`(?:kostenlose[rn]?\s+)?versand(?:kostenfrei|kosten|\s+(?:in|innerhalb|ab|ist|kostet))`,+ String.raw`lieferzeit|lieferung\s+(?:in|innerhalb)`,+ String.raw`livraison\s+(?:gratuite|offerte|en|sous|express|standard|sous)|exp[ée]di(?:tion|é(?:e|s)?)\s+(?:sous|en|le|gratuite)`,+ String.raw`env[ií]os?\s+(?:gratis|gratuito|en|a|de\s+\d)|entrega\s+(?:en|gratuita|gratis|de\s+\d)`,+ String.raw`(?:ücretsiz|bedava|hızlı|aynı\s+gün)\s+kargo|kargo\s+(?:ücretsiz|bedava|ücreti|süresi|ile|firması|bedeli)|kargoya\s+verilir|teslimat\s+(?:süresi|ücreti|bilgileri)|teslim\s+edilir`,+ ].join('|')})`,+ 'iu',+);+/**+ * Words that say how a product goes back: "30-day returns", "Returns are+ * accepted within 30 days", "free returns", "satisfait ou remboursé",+ * "kostenlose Retoure", "iade koşulları". Not "in return" or "return on+ * investment".+ */+const RETURN_WORDS = new RegExp(+ String.raw`(?<!\p{L})(?:${[+ String.raw`returns?\s+(?:policy|within|window|are\s+(?:free|accepted|easy)|is\s+free|accepted|and\s+exchanges?|&\s+exchanges?)`,+ String.raw`(?:free|easy|hassle[- ]free)\s+returns?|\d+[- ]days?\s+(?:returns?|money[- ]back|refund)`,+ String.raw`refunds?\s+(?:policy|within|in)|full\s+refund|money[- ]back`,+ String.raw`iade|değişim\s+(?:hakkı|süresi|koşulları)|ücretsiz\s+değişim`,+ String.raw`rückgabe|rücksendung|widerruf|(?:kostenlose\s+)?retoure|umtausch`,+ String.raw`retours?\s+(?:gratuits?|sous|accept[ée]s?|offerts?)|remboursement|satisfait\s+ou\s+rembours[ée]`,+ String.raw`devoluci[oó]n|reembolso`,+ ].join('|')})`,+ 'iu',+);+/** A heading that names the policy ("Shipping & Returns", "Versand", "İade"): it counts with text under it. */+const SHIPPING_HEADING =+ /^(?:shipping|delivery|shipping\s+(?:&|and)\s+(?:returns|delivery)|delivery\s+(?:&|and)\s+returns|versand(?:\s*(?:&|und)\s*(?:rückgabe|lieferung))?|lieferung|livraison(?:\s+et\s+retours)?|env[ií]os?(?:\s+y\s+devoluciones)?|kargo(?:\s+(?:ve|&)\s+iade)?|teslimat(?:\s+(?:ve|&)\s+iade)?)(?:\s+(?:policy|information|info|bilgileri|politikası))?[\s:]*$/iu;+const RETURN_HEADING =+ /^(?:(?:shipping|delivery)\s+(?:&|and)\s+)?(?:returns?(?:\s+(?:&|and)\s+(?:exchanges?|refunds?))?|refunds?|exchanges?|(?:versand\s*(?:&|und)\s*)?rückgabe|retours|(?:livraison\s+et\s+)?retours|(?:env[ií]os?\s+y\s+)?devoluciones|(?:kargo\s+(?:ve|&)\s+)?iade(?:\s+(?:ve|&)\s+değişim)?|değişim)(?:\s+(?:policy|information|info|koşulları|politikası))?[\s:]*$/iu;+/**+ * A link to the shop's shipping or returns page, by its own path+ * ("/shipping", "/pages/shipping-and-returns", "/policies/refund-policy",+ * "#returns"); not a product's ("/collections/delivery-bags").+ */+const SHIPPING_LINK =+ /(?:^|[/#])(?:shipping|delivery|kargo|teslimat|versand(?:kosten)?|lieferung|livraison|envios?)(?:[-_](?:policy|policies|info|information|and[-_](?:returns?|delivery)|returns?|bilgileri|politikasi))*\/?(?:$|[?#])/iu;+const RETURN_LINK =+ /(?:^|[/#])(?:(?:shipping|delivery)[-_]and[-_])?(?:returns?|refunds?|iade|rueckgabe|ruecksendung|widerruf|retours?|reembolsos?|devoluciones?)(?:[-_](?:policy|policies|info|information|and[-_](?:exchanges?|refunds?)|kosullari))*\/?(?:$|[?#])/iu;+/** The languages these words are written for: another page is read by its links alone. */+const SHIPPING_LANGUAGES = new Set(['en', 'tr', 'de', 'fr', 'es']);++/**+ * Whether a page says how its product ships and goes back (Phase 3,+ * CE-052): its words in a policy's terms, a heading that names the policy+ * with text under it, or a link to the shop's page for each. A product+ * page's to-do reads it before Trust does. Read as written and lowercased+ * the Turkish way too ("İade koşulları"). A page in a language these words+ * aren't written for is read by its links alone, and isn't asked (null)+ * when it has none.+ */+export function shippingOnPage(+ html: string,+ language: string | null = 'en',+): { shipping: boolean; returns: boolean } | null {+ const doc = new DOMParser().parseFromString(html, 'text/html');+ const blocks = [...doc.body.querySelectorAll('p, li, td, th, blockquote, h1, h2, h3, h4, h5, h6')]+ .map((el) => ({ heading: /^H\d$/.test(el.tagName), text: (el.textContent ?? '').trim() }))+ .filter((block) => block.text);+ const hrefs = [...doc.body.querySelectorAll('a[href]')].map((a) => a.getAttribute('href') ?? '');+ const linked = {+ shipping: hrefs.some((href) => SHIPPING_LINK.test(href)),+ returns: hrefs.some((href) => RETURN_LINK.test(href)),+ };+ if (!SHIPPING_LANGUAGES.has(languageCode(language) ?? '')) {+ return linked.shipping || linked.returns ? linked : null;+ }+ const read = (text: string, words: RegExp) =>+ words.test(text) || words.test(text.toLocaleLowerCase('tr'));+ // A heading that names the policy, with text under it before the next heading.+ const headed = (heading: RegExp) =>+ blocks.some(+ (block, i) =>+ block.heading && read(block.text, heading) && blocks[i + 1] && !blocks[i + 1].heading,+ );+ const says = (words: RegExp) => blocks.some((block) => read(block.text, words));+ return {+ shipping: linked.shipping || says(SHIPPING_WORDS) || headed(SHIPPING_HEADING),+ returns: linked.returns || says(RETURN_WORDS) || headed(RETURN_HEADING),+ };+}+/*** Trust's Phase 1 points (sourced figures, fresh sources, working links):* what a broken link's gain is out of while Trust isn't scored (trustGain).@@ -395,6 +499,8 @@ export interface TrustRead extends Score<TrustCheckId> {classified: number;/** Phase 2 (CE-047): the page's facts that differ from the brand's approved ones. */mismatches: FactMismatch[];+ /** Phase 3 (CE-052): whether the page says how shipping and returns work; null where not read. */+ shipping?: { shipping: boolean; returns: boolean } | null;}/**@@ -463,8 +569,14 @@ export function trust({brandFacts = null,proofs = null,page = null,+ shipping = null,now,}: {+ /**+ * Phase 3 (CE-052): whether a product page says how shipping and returns+ * work (shippingOnPage); left out elsewhere.+ */+ shipping?: { shipping: boolean; returns: boolean } | null;/** The page's blocks (trustBlocks). */blocks: TrustBlock[];/** Each link's read, by the link as the page has it; one not read yet isn't counted. */@@ -650,6 +762,16 @@ export function trust({});}+ const shippingSaid = shipping;+ if (shippingSaid) {+ checks.push({+ id: 'shippingReturns',+ points:+ (SHIPPING_POINTS * (Number(shippingSaid.shipping) + Number(shippingSaid.returns))) / 2,+ max: SHIPPING_POINTS,+ });+ }+// The site's 5 points weigh with what the page itself shows: alone, they'd// be the page's whole Trust.if (siteTrust && checks.length) {@@ -675,6 +797,7 @@ export function trust({weak,classified: classified.length,mismatches: brandFacts?.mismatches ?? [],+ shipping: shippingSaid,};}diff --git a/web/src/lib/content/quality-profiles.test.ts b/web/src/lib/content/quality-profiles.test.tsindex 34c97f9f6..b5d6fe72a 100644--- a/web/src/lib/content/quality-profiles.test.ts+++ b/web/src/lib/content/quality-profiles.test.ts@@ -54,8 +54,8 @@ describe('PROFILE_WEIGHTS', () => {it('asks a product page for no author, and a comparison for balance and a disclosure', () => {expect(checksOff('product')).toContain('byline');expect(checksOff('product')).toContain('authorBio');- // An article counts every check but the brand's own information.- expect([...checksOff('article')]).toEqual(['brandInfo']);+ // An article counts every check but the brand's information, the type rules and shipping.+ expect([...checksOff('article')].sort()).toEqual(['brandInfo', 'shippingReturns', 'typeRules']);expect(PROFILE_WEIGHTS.comparison.trust.balanced).toBeGreaterThan(PROFILE_WEIGHTS.article.trust.balanced,);@@ -156,7 +156,7 @@ describe('weighedTrust', () => {// A product page doesn't weigh freshness: a working link and the site aren't Trust.const product = weighedTrust(dated, PROFILE_WEIGHTS.product.trust);expect(product.score).toBeNull();- expect(product.phase1Points).toBe(40);+ expect(product.phase1Points).toBe(35);// A figure brings it in.const figure = read('<p>It cut costs by 40% (<a href="https://example.org/report">the report</a>).</p>',@@ -186,8 +186,8 @@ describe('weighedTrust', () => {now,});expect(priced.score).toBeNull();- // Brand facts 0 of 30, site trust 20 of 20: 40.- expect(weighedTrust(priced, PROFILE_WEIGHTS.product.trust).score).toBe(40);+ // Brand facts 0 of 30, site trust 15 of 15: 33.+ expect(weighedTrust(priced, PROFILE_WEIGHTS.product.trust).score).toBe(33);expect(weighedTrust(priced, PROFILE_WEIGHTS.category.trust).score).not.toBeNull();// An article weighs them 10 to its claims' 30: a price alone isn't its Trust.expect(weighedTrust(priced, PROFILE_WEIGHTS.article.trust).score).toBeNull();diff --git a/web/src/lib/content/quality-profiles.ts b/web/src/lib/content/quality-profiles.tsindex 423243f8e..d4a989b39 100644--- a/web/src/lib/content/quality-profiles.ts+++ b/web/src/lib/content/quality-profiles.ts@@ -71,7 +71,8 @@ export const PROFILE_WEIGHTS: Readonly<Record<QualityProfile, ProfileWeights>> =readability: { ...READABILITY_WEIGHTS },},// No author (the brand's byline); real product photos; proof for its- // claims and prices that match; short, plain copy.+ // claims, prices that match, how it ships and goes back; short, plain+ // copy with its specs table.product: {eeat: {experience: 20,@@ -85,7 +86,7 @@ export const PROFILE_WEIGHTS: Readonly<Record<QualityProfile, ProfileWeights>> =brandInfo: 0,},trust: {- claimsSourced: 30,+ claimsSourced: 25,primarySources: 5,noWeakSources: 5,brandFacts: 30,@@ -94,21 +95,23 @@ export const PROFILE_WEIGHTS: Readonly<Record<QualityProfile, ProfileWeights>> =balanced: 0,disclosure: 0,noBrokenLinks: 10,- siteTrust: 20,+ siteTrust: 15,+ shippingReturns: 10,},readability: {- avgSentence: 20,- longSentences: 25,- readingLevel: 25,+ avgSentence: 15,+ longSentences: 20,+ readingLevel: 20,answerFirst: 0,- shortParagraphs: 20,+ shortParagraphs: 15,headingSpacing: 0,passiveJargon: 10,+ typeRules: 20,},},// Low E-E-A-T weight: real product images and the brand's own// information (its site's trust); prices and claims that match the- // brand's; a short intro.+ // brand's; a short intro and a buying FAQ.category: {eeat: {experience: 0,@@ -132,15 +135,17 @@ export const PROFILE_WEIGHTS: Readonly<Record<QualityProfile, ProfileWeights>> =disclosure: 0,noBrokenLinks: 15,siteTrust: 25,+ shippingReturns: 0,},readability: {- avgSentence: 25,- longSentences: 25,- readingLevel: 25,+ avgSentence: 15,+ longSentences: 20,+ readingLevel: 20,answerFirst: 0,- shortParagraphs: 25,+ shortParagraphs: 15,headingSpacing: 0,passiveJargon: 0,+ typeRules: 30,},},// Product screenshots weigh most, then the person's data and use;@@ -168,19 +173,22 @@ export const PROFILE_WEIGHTS: Readonly<Record<QualityProfile, ProfileWeights>> =disclosure: 0,noBrokenLinks: 5,siteTrust: 10,+ shippingReturns: 0,},readability: {- avgSentence: 20,+ avgSentence: 15,longSentences: 15,readingLevel: 15,answerFirst: 10,- shortParagraphs: 20,+ shortParagraphs: 15,headingSpacing: 15,passiveJargon: 5,+ typeRules: 10,},},// An author, saying how the picks were made; balance and a disclosure,- // each rival's facts from its own pages; the summary first.+ // each rival's facts from its own pages; the summary first and a table+ // side by side.comparison: {eeat: {experience: 20,@@ -204,15 +212,17 @@ export const PROFILE_WEIGHTS: Readonly<Record<QualityProfile, ProfileWeights>> =disclosure: 15,noBrokenLinks: 5,siteTrust: 5,+ shippingReturns: 0,},readability: {- avgSentence: 20,- longSentences: 15,+ avgSentence: 15,+ longSentences: 10,readingLevel: 15,answerFirst: 25,shortParagraphs: 10,- headingSpacing: 10,+ headingSpacing: 5,passiveJargon: 5,+ typeRules: 15,},},};diff --git a/web/src/lib/content/quality-todos.test.ts b/web/src/lib/content/quality-todos.test.tsindex 1af371c90..32d9e8e8c 100644--- a/web/src/lib/content/quality-todos.test.ts+++ b/web/src/lib/content/quality-todos.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';import type { ContentAuthor } from './authors';import type { PageProof } from './page-read';import { eeat, trust, trustBlocks } from './quality-checks';-import { PROFILE_WEIGHTS, checksOff, weighed } from './quality-profiles';+import { PROFILE_WEIGHTS, checksOff, weighed, weighedTrust } from './quality-profiles';import { proofKey, qualityTodos } from './quality-todos';/** Your to-dos (Quality spec §4, CE-040): only what the person can do, read from the checks. */@@ -49,6 +49,60 @@ describe('qualityTodos', () => {]);});+ it('asks a product page to say how shipping and returns work: only the person knows (CE-052)', () => {+ const base = {+ eeat: weighed(+ eeat({ author: null, used: { experience: true, data: true } }),+ PROFILE_WEIGHTS.product.eeat,+ ),+ author: null,+ hasAuthors: true,+ };+ const ships = (shipping: boolean, returns: boolean) =>+ qualityTodos({ ...base, shipping: { shipping, returns }, off: checksOff('product') }).find(+ (t) => t.id === 'shippingReturns',+ );+ expect(ships(true, false)).toMatchObject({ done: false, score: 'trust', action: null });+ expect(ships(true, true)).toMatchObject({ done: true, gain: 0 });+ // With Trust scored, its gain is the check's share.+ const scored = weighedTrust(+ trust({+ blocks: trustBlocks('<p>Win rates rose 42% last year.</p>'),+ links: new Map(),+ brandDomains: ['acme.com'],+ shipping: { shipping: true, returns: false },+ now: Date.parse('2026-10-25'),+ }),+ PROFILE_WEIGHTS.product.trust,+ );+ expect(+ qualityTodos({+ ...base,+ trust: scored,+ shipping: { shipping: true, returns: false },+ off: checksOff('product'),+ }).find((t) => t.id === 'shippingReturns')!.gain,+ ).toBeGreaterThan(0);+ // Before E-E-A-T is read, the type's checks are left out all the same.+ expect(+ qualityTodos({+ eeat: null,+ author: null,+ hasAuthors: true,+ shipping: { shipping: false, returns: false },+ off: checksOff('feature'),+ }),+ ).toEqual([]);+ // Another type doesn't ask.+ expect(+ qualityTodos({+ ...base,+ shipping: { shipping: false, returns: false },+ off: checksOff('feature'),+ }).some((t) => t.id === 'shippingReturns'),+ ).toBe(false);+ });+it('asks to add an author when the workspace has none', () => {expect(todos(null, false)[0]).toEqual({id: 'byline',diff --git a/web/src/lib/content/quality-todos.ts b/web/src/lib/content/quality-todos.tsindex c332dbcbf..dfd3889b5 100644--- a/web/src/lib/content/quality-todos.ts+++ b/web/src/lib/content/quality-todos.ts@@ -33,7 +33,8 @@ export type QualityTodoId =| 'expertQuote'| 'proof'| 'reviewer'- | 'brandFacts';+ | 'brandFacts'+ | 'shippingReturns';/*** A to-do's one button: Show (the first placeholder, selected to type over),@@ -102,6 +103,7 @@ export function qualityTodos({visual = null,reviewer = null,confirmed = null,+ shipping = null,off = NONE_OFF,}: {eeat: Score<EeatCheckId> | null;@@ -144,6 +146,11 @@ export function qualityTodos({reviewer?: { topic: 'health' | 'finance' | 'legal'; picked: boolean } | null;/** What the person confirmed of the author their site names (00271), or null where they can't. */confirmed?: { real: boolean; profile: boolean } | null;+ /**+ * Phase 3 (CE-052): whether a product page says how shipping and returns+ * work (Trust's read): only the person knows them.+ */+ shipping?: { shipping: boolean; returns: boolean } | null;/*** Phase 3 (CE-052): the checks the page's type leaves out (checksOff): no* to-do asks for them (a product page has the brand's byline, no author).@@ -196,6 +203,20 @@ export function qualityTodos({} satisfies QualityTodo,];});+ const ships: QualityTodo[] = shipping+ ? [+ {+ id: 'shippingReturns',+ done: shipping.shipping && shipping.returns,+ gain:+ trust && trust.score !== null && !(shipping.shipping && shipping.returns)+ ? scoreGain(trust, ['shippingReturns'])+ : 0,+ score: 'trust',+ action: null,+ },+ ]+ : [];const review: QualityTodo[] = reviewer? [{@@ -208,7 +229,11 @@ export function qualityTodos({},]: [];- if (!eeat || eeat.score === null) return [...fill, ...proofTodos, ...review, ...facts];+ if (!eeat || eeat.score === null) {+ return [...fill, ...proofTodos, ...ships, ...review, ...facts].filter(+ (todo) => !off.has(todo.id),+ );+ }// No author picked: the one the site names may be confirmed instead, the// profile once the author is.const byConfirm = !author && !!confirmed;@@ -273,6 +298,7 @@ export function qualityTodos({] satisfies QualityTodo[]): []),...proofTodos,+ ...ships,...review,...facts,];diff --git a/web/src/lib/content/readability.test.ts b/web/src/lib/content/readability.test.tsindex 9c8162ec1..59a5932d0 100644--- a/web/src/lib/content/readability.test.ts+++ b/web/src/lib/content/readability.test.ts@@ -9,6 +9,7 @@ import {readabilityGain,sentencesOf,syllablesOf,+ withTypeRules,} from './readability';/** Readability (Quality spec §2.3, CE-036): seven checks read from the draft as written. */@@ -449,3 +450,39 @@ describe('the parts', () => {for (const { code } of LANGUAGES) expect(languageCode(languageRuleValue(code))).toBe(code);});});++describe('withTypeRules (Phase 3, CE-052)', () => {+ const html = `<h1>Pipeline</h1>${p(Array.from({ length: 6 }, () => sentence(15)).join(' '))}`;++ it('counts the page type’s rules met as one check, naming the ones not met', () => {+ const read = readability(html, 'en');+ const typed = withTypeRules(read, [+ { name: 'Specs table', met: false, detail: 'Now: missing' },+ { name: 'Fit questions', met: true },+ ]);+ const rules = typed.checks.find((c) => c.id === 'typeRules')!;+ expect(rules).toMatchObject({+ points: 5,+ max: 10,+ count: 1,+ rules: [{ name: 'Specs table', detail: 'Now: missing' }],+ });+ // Rescaled with it.+ const points = read.checks.reduce((sum, c) => sum + c.points, 0);+ const max = read.checks.reduce((sum, c) => sum + c.max, 0);+ expect(typed.score).toBe(Math.round(((points + 5) / (max + 10)) * 100));+ // All met: full points.+ expect(+ withTypeRules(read, [{ name: 'Specs table', met: true }]).checks.find(+ (c) => c.id === 'typeRules',+ ),+ ).toMatchObject({ points: 10, count: 0 });+ });++ it('adds none to a page too short to read, or with no type rules', () => {+ const short = readability(`<h1>Pipeline</h1>${p(sentence(10))}`, 'en');+ expect(withTypeRules(short, [{ name: 'Specs table', met: false }])).toBe(short);+ const read = readability(html, 'en');+ expect(withTypeRules(read, [])).toBe(read);+ });+});diff --git a/web/src/lib/content/readability.ts b/web/src/lib/content/readability.tsindex 24ed3779c..e2c34fc42 100644--- a/web/src/lib/content/readability.ts+++ b/web/src/lib/content/readability.ts@@ -16,10 +16,15 @@ export const READABILITY_CHECKS = ['shortParagraphs','headingSpacing','passiveJargon',+ // Phase 3 (CE-052): the page type's own rules, as the Rules tab reads them.+ 'typeRules',] as const;export type ReadabilityCheckId = (typeof READABILITY_CHECKS)[number];-/** Each check's weight (spec §2.3): 100 in all. */+/**+ * Each check's weight (spec §2.3): 100 in all. The page type's rules count+ * only on the types that weigh them (quality-profiles.ts).+ */export const READABILITY_WEIGHTS: Record<ReadabilityCheckId, number> = {avgSentence: 25,longSentences: 15,@@ -28,6 +33,7 @@ export const READABILITY_WEIGHTS: Record<ReadabilityCheckId, number> = {shortParagraphs: 10,headingSpacing: 10,passiveJargon: 5,+ typeRules: 0,};/** A sentence longer than this is long (spec: "No sentence over 35 words"). */@@ -75,6 +81,8 @@ export interface ReadabilityCheck {ai?: boolean;/** The first block that falls short, to show it in the draft. */at?: string | null;+ /** The page type's rules not met yet, by name, each with its aim and how the page reads now (typeRules). */+ rules?: { name: string; detail: string }[];}export interface Readability {@@ -574,6 +582,37 @@ export function readability(return { score: Math.round((points / max) * 100), checks, words };}+/** The type rules check's points before a page type weighs it (weighed keeps its share). */+const TYPE_RULES_POINTS = 10;++/**+ * The page type's own rules as one Readability check (Phase 3, CE-052): the+ * Rules tab's, read from the page (a specs table, a side-by-side table, an+ * intro, a buying FAQ), their share met; the ones turned off there aren't+ * counted. A page too short to read, or a type with none, has none.+ */+export function withTypeRules(+ read: Readability,+ rules: readonly { name: string; met: boolean; detail?: string }[],+): Readability {+ if (read.score === null || rules.length === 0) return read;+ const met = rules.filter((r) => r.met).length;+ const checks: ReadabilityCheck[] = [+ ...read.checks,+ {+ id: 'typeRules',+ points: (TYPE_RULES_POINTS * met) / rules.length,+ max: TYPE_RULES_POINTS,+ value: rules.length,+ count: rules.length - met,+ rules: rules.filter((r) => !r.met).map((r) => ({ name: r.name, detail: r.detail ?? '' })),+ },+ ];+ const max = checks.reduce((sum, c) => sum + c.max, 0);+ const points = checks.reduce((sum, c) => sum + c.points, 0);+ return { ...read, checks, score: Math.round((points / max) * 100) };+}+/** How much a check would add to the score if it were met, rescaled as the score is. */export function readabilityGain(result: Readability, id: ReadabilityCheckId): number {const c = result.checks.find((x) => x.id === id);diff --git a/web/src/lib/content/rules.test.ts b/web/src/lib/content/rules.test.tsindex 00ee8f9d4..e99ec87ad 100644--- a/web/src/lib/content/rules.test.ts+++ b/web/src/lib/content/rules.test.ts@@ -468,6 +468,39 @@ describe('page type rules', () => {).toEqual({ state: 'bad', code: 'current', count: 40 });});+ it('asks a product with sizes for fit questions, and one without none (#1494 review)', () => {+ const sized = '<table><tr><th>Sizes</th><td>XS–XL</td></tr></table>';+ expect(check('fitQuestions', sized, '3', 'product_page')).toEqual({+ state: 'bad',+ code: 'partOf',+ count: 0,+ of: 3,+ });+ expect(+ check('fitQuestions', '<p>A burr grinder for espresso.</p>', '3', 'product_page'),+ ).toEqual({ state: 'info', code: 'noSizes' });+ });++ it('reads a buying FAQ under its heading in the page’s language (#1494 review)', () => {+ const faq = (heading: string, language: string) =>+ checkRule(+ rule('buyingFaq', 'category_page', '2'),+ page(`<h2>${heading}</h2><h3>Q1?</h3><p>A.</p><h3>Q2?</h3><p>B.</p>`),+ { ...ctx, language },+ );+ for (const [heading, language] of [+ ['Häufig gestellte Fragen', 'de'],+ ['Questions fréquentes', 'fr'],+ ['Preguntas frecuentes', 'es'],+ ['SIKÇA SORULAN SORULAR', 'tr'],+ ]) {+ expect(faq(heading, language)).toEqual({ state: 'ok' });+ }+ // A language whose heading isn't read: its FAQ isn't said to be missing.+ expect(faq('Vanliga frågor', 'sv')).toEqual({ state: 'info', code: 'englishOnly' });+ expect(faq('Materials', 'en')).toEqual({ state: 'bad', code: 'missing' });+ });+it('checks a destination page’s summary', () => {expect(check(@@ -529,6 +562,14 @@ describe('the formats www.ansvisor.com offers', () => {expect(define('<h1>Cold brew</h1><p>Cold brew is, simply, coffee steeped cold.</p>')).toEqual({state: 'ok',});+ // Fit questions too: a Turkish product page isn't scored on English words (CE-052).+ expect(+ checkRule(+ rule('fitQuestions', 'product_page'),+ page('<h1>Yürüyüş çantası</h1><h2>Hangi beden bana uyar?</h2><p>Ölçü tablosuna bakın.</p>'),+ { ...ctx, language: 'tr' },+ ),+ ).toEqual({ state: 'info', code: 'englishOnly' });// Read in English words only: another language's page isn't counted.expect(checkRule(diff --git a/web/src/lib/content/rules.ts b/web/src/lib/content/rules.tsindex bfe2ecfc3..9f117d4e2 100644--- a/web/src/lib/content/rules.ts+++ b/web/src/lib/content/rules.ts@@ -4,7 +4,7 @@ import { classifyDomain, normalizeDomain } from '@/lib/citations/classify';import { PAGE_TYPES, type DraftMethod, type PageType } from '@/lib/content/drafts';import { lengthTarget } from '@/lib/content/editor';import { decodeHtmlBlock } from '@/lib/content/html-allowlist';-import { countWords } from '@/lib/content/readability';+import { countWords, languageCode } from '@/lib/content/readability';import { wordsOf } from '@/lib/content/sources';/**@@ -600,7 +600,14 @@ export type RuleStatus =| { state: 'bad'; code: 'needsFaq'; missing?: string[] }| {state: 'info';- code: 'aiCheck' | 'needsFeed' | 'noFanouts' | 'addKeywords' | 'notHowTo' | 'englishOnly';+ code:+ | 'aiCheck'+ | 'needsFeed'+ | 'noFanouts'+ | 'addKeywords'+ | 'notHowTo'+ | 'englishOnly'+ | 'noSizes';};export interface RuleContext {@@ -664,11 +671,27 @@ function carries(fanout: string, text: string): boolean {return words.filter((w) => have.has(w)).length / words.length >= 0.75;}+/**+ * An FAQ's heading, in the languages it's read in ("FAQ", "Häufig gestellte+ * Fragen", "Questions fréquentes", "Preguntas frecuentes", "Sıkça Sorulan+ * Sorular"…), lowercased the Turkish way too.+ */+const FAQ_HEADING =+ /(?<!\p{L})(?:faqs?|frequently asked|häufig gestellte fragen|häufige fragen|questions fréquentes|foire aux questions|preguntas frecuentes|sıkça sorulan sorular|sık sorulan sorular|sss|domande frequenti|perguntas frequentes|veelgestelde vragen)(?!\p{L})/iu;+/**+ * A product's sizes on its page: a size chart or guide, "sizes", letter+ * sizes or a country's numbered ones ("XS", "XL", "EU 42", "US 9.5").+ */+const SIZES =+ /(?<!\p{L})(?:size\s+(?:chart|guide|table)|sizes|sizing|xxs|xs|xl|xxl|xxxl|(?:eu|us|uk)\s?\d{1,2}(?:[.,]5)?)(?!\p{L})/iu;+/** The languages an FAQ's heading is read in: another page's missing FAQ isn't said. */+const FAQ_LANGUAGES = new Set(['en', 'de', 'fr', 'es', 'tr', 'it', 'pt', 'nl']);+const isFaqHeading = (text: string) =>+ FAQ_HEADING.test(text) || FAQ_HEADING.test(text.toLocaleLowerCase('tr'));+/** The FAQ's questions: the blocks after an "FAQ" heading, up to the next H2, that ask one. */function faqQuestions(blocks: PageBlock[]): string[] | null {- const start = blocks.findIndex(- (b) => (b.tag === 'h2' || b.tag === 'h3') && /\b(faq|faqs|frequently asked)\b/i.test(b.text),- );+ const start = blocks.findIndex((b) => (b.tag === 'h2' || b.tag === 'h3') && isFaqHeading(b.text));if (start < 0) return null;const level = blocks[start].tag;const questions: string[] = [];@@ -939,7 +962,12 @@ export function checkRule(rule: ActiveRule, page: PageRead, ctx: RuleContext): Rcase 'faq':case 'buyingFaq': {const questions = faqQuestions(blocks);- if (!questions) return { state: 'bad', code: 'missing' };+ if (!questions) {+ // A language whose FAQ heading isn't read: not said to be missing.+ return FAQ_LANGUAGES.has(languageCode(ctx.language) ?? '')+ ? { state: 'bad', code: 'missing' }+ : { state: 'info', code: 'englishOnly' };+ }return atLeast(questions.length, n);}case 'fanoutFaq': {@@ -1028,12 +1056,18 @@ export function checkRule(rule: ActiveRule, page: PageRead, ctx: RuleContext): R);return most ? atLeast(most, n) : { state: 'bad', code: 'missing' };}- case 'fitQuestions':- return atLeast(- blocks.filter((b) => isQuestion(b) && /\b(fit|fits|size|sizes|sizing)\b/i.test(b.text))- .length,- n,- );+ case 'fitQuestions': {+ // Read in English only ("fit", "size"): another language's page isn't scored on it.+ if (ctx.language && ctx.language !== 'en') return { state: 'info', code: 'englishOnly' };+ const asked = blocks.filter(+ (b) => isQuestion(b) && /\b(fit|fits|size|sizes|sizing)\b/i.test(b.text),+ ).length;+ // A product with no sizes (a coffee grinder) has no fit to ask about.+ if (!asked && !blocks.some((b) => SIZES.test(b.text))) {+ return { state: 'info', code: 'noSizes' };+ }+ return atLeast(asked, n);+ }case 'introText': {const words = blocks.slice(h1 + 1, firstH2 < 0 ? undefined : firstH2)