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(action-center): show on Analyze competitor content what the competitor pages AI cites have that yours doesn't (learning C1) (#1720)
Cihan9333a329e592
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 667948f94..202a075c0 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -1628,7 +1628,27 @@"openDraft": "Open draft","pagesToOptimize": "Pages to optimize","draftFailed": "Couldn't open the Content Editor. Try again.",- "pageNotRead": "Couldn't read the live page, so the draft starts with its title. Paste the page into the editor."+ "pageNotRead": "Couldn't read the live page, so the draft starts with its title. Paste the page into the editor.",+ "competitor": {+ "title": "What the pages AI cites instead of yours have",+ "gap": "— on {count} of {of} of their pages, not on yours",+ "gapNoPage": "— on {count} of {of} of their pages",+ "noGap": "Your page passes every check at least half of their pages pass.",+ "tooFew": "Only one of their pages was read: it takes at least two to say what theirs have that yours doesn't.",+ "pages": "{count, plural, one {The page read} other {The # pages read}}",+ "yours": "Your page cited for these prompts",+ "noPage": "None of your pages was cited for these prompts lately.",+ "yourUnreadable": "Your page cited for these prompts couldn't be read: it may block readers.",+ "words": "{count, plural, one {# word} other {{words} words}}",+ "cited": "cited in {count, plural, one {# answer} other {# answers}}",+ "note": "Read from their public pages and run through Site Audit's checks; only what the checks found is kept.",+ "unreadable": "{count, plural, one {# page} other {# pages}} couldn't be read.",+ "reasons": {+ "no_prompts": "There are no tracked prompts to read the answers of for this action.",+ "none_cited": "In the last two weeks, AI answers for these prompts cited no competitor page, and no page in answers that don't name your brand.",+ "unreadable": "The pages cited couldn't be read: they may block readers."+ }+ }},"noSignalsOpportunity": "This action was sent from Content Optimization. Its evidence is the opportunity on the Overview tab, not detection signals.","opportunity": {diff --git a/web/src/components/action-center/action-drawer.tsx b/web/src/components/action-center/action-drawer.tsxindex c6cc94905..93ae02407 100644--- a/web/src/components/action-center/action-drawer.tsx+++ b/web/src/components/action-center/action-drawer.tsx@@ -1050,6 +1050,7 @@ function TaskRow({send={send}check={check}draftWork={draftWork}+ competitor={task.competitorFindings}/>))}diff --git a/web/src/components/action-center/competitor-findings.tsx b/web/src/components/action-center/competitor-findings.tsxnew file mode 100644index 000000000..8bf9a9bb9--- /dev/null+++ b/web/src/components/action-center/competitor-findings.tsx@@ -0,0 +1,103 @@+'use client';++import { useTranslations } from 'next-intl';+import { ArrowUpRight } from 'lucide-react';+import type { CitedPageRead, CompetitorFindings } from '@/lib/action-center/competitor-findings';+import { formatNumber } from '@/lib/format';++/** A page read, as a link: its host and path. */+function PageLink({ page }: { page: CitedPageRead }) {+ const t = useTranslations('actionCenter.actionsPage.drawer.task.competitor');+ const shown = page.url.replace(/^https?:\/\/(www\.)?/i, '').replace(/\/$/, '');+ return (+ <li className="flex flex-wrap items-baseline gap-x-2">+ <a+ href={page.url}+ target="_blank"+ rel="noopener noreferrer"+ className="break-all underline-offset-2 hover:underline"+ >+ {shown}+ <ArrowUpRight className="ml-0.5 inline h-3 w-3" />+ </a>+ <span className="text-muted-foreground">+ {[+ page.words !== null+ ? t('words', { count: page.words, words: formatNumber(page.words) })+ : null,+ page.cited > 0 ? t('cited', { count: page.cited }) : null,+ ]+ .filter(Boolean)+ .join(' · ')}+ </span>+ </li>+ );+}++/**+ * What the "Analyze competitor content" task found (learning C1): the checks+ * at least half of the competitor pages AI answers cite pass that the brand's+ * page doesn't, and the pages read; or why nothing was compared.+ */+export function CompetitorFindingsView({ findings }: { findings: CompetitorFindings }) {+ const t = useTranslations('actionCenter.actionsPage.drawer.task.competitor');+ const read = findings.competitorPages.length;++ return (+ <div className="space-y-2 text-xs">+ <p className="font-medium">{t('title')}</p>+ {read === 0 ? (+ <p className="text-muted-foreground">{t(`reasons.${findings.reason ?? 'unreadable'}`)}</p>+ ) : (+ <>+ {!findings.compared ? (+ <p className="text-muted-foreground">{t('tooFew')}</p>+ ) : findings.gaps.length > 0 ? (+ <ul className="space-y-1">+ {findings.gaps.map((gap) => (+ <li key={gap.key} className="flex gap-1.5">+ <span aria-hidden className="mt-1.5 h-1 w-1 shrink-0 rounded-full bg-current" />+ <span>+ <span className="font-medium">{gap.label}</span>{' '}+ <span className="text-muted-foreground">+ {t(findings.yourPage ? 'gap' : 'gapNoPage', {+ count: gap.competitors,+ of: gap.of,+ })}+ </span>+ </span>+ </li>+ ))}+ </ul>+ ) : (+ <p className="text-muted-foreground">{t('noGap')}</p>+ )}+ <div>+ <p className="text-muted-foreground">{t('pages', { count: read })}</p>+ <ul className="mt-0.5 space-y-0.5">+ {findings.competitorPages.map((page) => (+ <PageLink key={page.url} page={page} />+ ))}+ </ul>+ </div>+ <div>+ <p className="text-muted-foreground">{t('yours')}</p>+ {findings.yourPage ? (+ <ul className="mt-0.5">+ <PageLink page={findings.yourPage} />+ </ul>+ ) : (+ <p>{t(findings.yourPageStatus === 'unreadable' ? 'yourUnreadable' : 'noPage')}</p>+ )}+ </div>+ </>+ )}+ <p className="text-[11px] text-muted-foreground">+ {t('note')}+ {findings.unreadable > 0 &&+ read > 0 &&+ ` ${t('unreadable', { count: findings.unreadable })}`}+ </p>+ </div>+ );+}diff --git a/web/src/components/action-center/task-detail.test.tsx b/web/src/components/action-center/task-detail.test.tsxindex 4717bab19..443da75ed 100644--- a/web/src/components/action-center/task-detail.test.tsx+++ b/web/src/components/action-center/task-detail.test.tsx@@ -370,3 +370,102 @@ describe('sending a task (AC-004)', () => {expect([...container.querySelectorAll('button')].map((b) => b.textContent)).toEqual(['Edit']);});});++/** What Analyze competitor content found (learning C1), shown on the task. */+describe('TaskDetailView with competitor findings', () => {+ const findings = {+ competitorPages: [+ {+ url: 'https://rival.com/kettles/',+ domain: 'rival.com',+ cited: 4,+ words: 1200,+ passes: ['faq-schema'],+ },+ {+ url: 'https://blog.example/best',+ domain: 'blog.example',+ cited: 1,+ words: null,+ passes: [],+ },+ ],+ yourPage: {+ url: 'https://acme.com/kettles',+ domain: 'acme.com',+ cited: 1,+ words: 1,+ passes: [],+ },+ yourPageStatus: 'read' as const,+ gaps: [{ key: 'faq-schema', label: 'FAQ schema', competitors: 2, of: 2 }],+ compared: true,+ unreadable: 0,+ reason: null,+ };++ it('says which checks their pages pass and yours does not, and the pages read', () => {+ render(+ <TaskDetailView details={null} disabled={false} onEdit={() => {}} competitor={findings} />,+ );+ const text = container.textContent!;+ expect(text).toContain('What the pages AI cites instead of yours have');+ expect(text).toContain('FAQ schema — on 2 of 2 of their pages, not on yours');+ expect(text).toContain('The 2 pages read');+ expect(text).toContain('rival.com/kettles1,200 words · cited in 4 answers');+ expect(text).toContain('acme.com/kettles1 word · cited in 1 answer');+ expect(text).not.toContain('tomorrow');+ expect(container.querySelector('a[href="https://rival.com/kettles/"]')).not.toBeNull();+ });++ it('says why nothing was compared', () => {+ render(+ <TaskDetailView+ details={null}+ disabled={false}+ onEdit={() => {}}+ competitor={{ ...findings, competitorPages: [], gaps: [], reason: 'none_cited' }}+ />,+ );+ expect(container.textContent).toContain(+ "In the last two weeks, AI answers for these prompts cited no competitor page, and no page in answers that don't name your brand.",+ );+ });++ it('says when one page of theirs is too few to compare', () => {+ render(+ <TaskDetailView+ details={null}+ disabled={false}+ onEdit={() => {}}+ competitor={{+ ...findings,+ competitorPages: findings.competitorPages.slice(0, 1),+ gaps: [],+ compared: false,+ }}+ />,+ );+ expect(container.textContent).toContain(+ "Only one of their pages was read: it takes at least two to say what theirs have that yours doesn't.",+ );+ expect(container.textContent).not.toContain('Your page passes');+ });++ it("says the brand's page couldn't be read rather than that it wasn't cited", () => {+ render(+ <TaskDetailView+ details={null}+ disabled={false}+ onEdit={() => {}}+ competitor={{ ...findings, yourPage: null, yourPageStatus: 'unreadable', unreadable: 1 }}+ />,+ );+ const text = container.textContent!;+ expect(text).toContain(+ "Your page cited for these prompts couldn't be read: it may block readers.",+ );+ expect(text).not.toContain('None of your pages was cited');+ expect(text).toContain('FAQ schema — on 2 of 2 of their pages');+ });+});diff --git a/web/src/components/action-center/task-detail.tsx b/web/src/components/action-center/task-detail.tsxindex e6ccd60b7..9b4fa2025 100644--- a/web/src/components/action-center/task-detail.tsx+++ b/web/src/components/action-center/task-detail.tsx@@ -31,6 +31,8 @@ import { findActionDraft, type ActionDraft } from '@/lib/content/action-drafts';import { contentEditorPath, type DraftMethod } from '@/lib/content/drafts';import { pagePath } from '@/lib/content/overlap';import { cn } from '@/lib/utils';+import type { CompetitorFindings } from '@/lib/action-center/competitor-findings';+import { CompetitorFindingsView } from './competitor-findings';/** The type of work, beside the task's text (AC-004). */export function TaskTypeBadge({ type }: { type: ActionTaskDetails['type'] }) {@@ -133,6 +135,7 @@ export function TaskDetailView({send,draftWork,check,+ competitor = null,}: {details: ActionTaskDetails | null;disabled: boolean;@@ -142,6 +145,8 @@ export function TaskDetailView({draftWork?: TaskDraftWork;/** Check now, for a task checked automatically (AC-010). */check?: TaskCheckOptions;+ /** What Analyze competitor content found (learning C1). */+ competitor?: CompetitorFindings | null;}) {const t = useTranslations('actionCenter.actionsPage.drawer.task');const tChecks = useTranslations('actionCenter.taskChecks');@@ -154,6 +159,7 @@ export function TaskDetailView({return (<div className="space-y-2 border-t px-4 py-3">+ {competitor && <CompetitorFindingsView findings={competitor} />}{details?.body && (<p className="text-xs leading-relaxed whitespace-pre-line text-muted-foreground">{details.body}diff --git a/web/src/lib/action-center/competitor-findings.test.ts b/web/src/lib/action-center/competitor-findings.test.tsnew file mode 100644index 000000000..d8b76881d--- /dev/null+++ b/web/src/lib/action-center/competitor-findings.test.ts@@ -0,0 +1,77 @@+import { describe, expect, it } from 'vitest';+import { parseCompetitorFindings } from './competitor-findings';++/** What Analyze competitor content stored (learning C1), read defensively. */+describe('parseCompetitorFindings', () => {+ it('reads the pages, the brand page and the gaps', () => {+ expect(+ parseCompetitorFindings({+ competitorPages: [+ {+ url: 'https://rival.com/kettles',+ domain: 'rival.com',+ cited: 4,+ words: 1200,+ passes: ['faq-schema', 3],+ },+ { url: 'javascript:alert(1)', cited: 1 },+ ],+ yourPage: { url: 'https://acme.com/kettles', cited: 1, words: null, passes: [] },+ gaps: [+ { key: 'faq-schema', label: 'FAQ schema', competitors: 2, of: 3 },+ { key: 'tables', competitors: 1, of: 0 },+ ],+ yourPageStatus: 'read',+ compared: true,+ unreadable: 0,+ }),+ ).toEqual({+ competitorPages: [+ {+ url: 'https://rival.com/kettles',+ domain: 'rival.com',+ cited: 4,+ words: 1200,+ passes: ['faq-schema'],+ },+ ],+ yourPage: {+ url: 'https://acme.com/kettles',+ domain: null,+ cited: 1,+ words: null,+ passes: [],+ },+ yourPageStatus: 'read',+ gaps: [{ key: 'faq-schema', label: 'FAQ schema', competitors: 2, of: 3 }],+ compared: true,+ unreadable: 0,+ reason: null,+ });+ });++ it("reads whether the brand's page was read and whether theirs were compared", () => {+ const base = { competitorPages: [], yourPage: null, gaps: [] };+ expect(+ parseCompetitorFindings({ ...base, yourPageStatus: 'unreadable', compared: false }),+ ).toMatchObject({ yourPageStatus: 'unreadable', compared: false });+ // Not cited unless it says it couldn't be read; compared unless it says not.+ expect(parseCompetitorFindings({ ...base, yourPageStatus: 'odd' })).toMatchObject({+ yourPageStatus: 'not_cited',+ compared: true,+ });+ });++ it("reads why nothing was compared, and nothing from another tool's output", () => {+ expect(+ parseCompetitorFindings({+ competitorPages: [],+ yourPage: null,+ gaps: [],+ reason: 'none_cited',+ })?.reason,+ ).toBe('none_cited');+ expect(parseCompetitorFindings({ answers: 100 })).toBeNull();+ expect(parseCompetitorFindings(null)).toBeNull();+ });+});diff --git a/web/src/lib/action-center/competitor-findings.ts b/web/src/lib/action-center/competitor-findings.tsnew file mode 100644index 000000000..c92dfc4d3--- /dev/null+++ b/web/src/lib/action-center/competitor-findings.ts@@ -0,0 +1,98 @@+/**+ * What the "Analyze competitor content" task found (learning C1): the pages+ * AI answers cited for the action's prompts where the brand isn't named, read+ * overnight and run through Site Audit's checks, the brand's own page beside+ * them, and the checks most of theirs pass that the brand's doesn't. The+ * task's output, as the API's action-center/competitor-pages.js writes it.+ */++/** The task whose output this is. */+export const COMPETITOR_TASK_KEY = 'analyze_competitor_content';++export interface CitedPageRead {+ url: string;+ domain: string | null;+ /** Answers that cited it, of those read. */+ cited: number;+ words: number | null;+ /** Site Audit check keys it passes. */+ passes: string[];+}++export interface CompetitorGap {+ key: string;+ /** The check's name, as Site Audit's rubric gives it. */+ label: string;+ /** Competitor pages passing it, of those read. */+ competitors: number;+ of: number;+}++export interface CompetitorFindings {+ competitorPages: CitedPageRead[];+ yourPage: CitedPageRead | null;+ /** Whether the brand's page was read, wasn't cited, or couldn't be read. */+ yourPageStatus: 'read' | 'not_cited' | 'unreadable';+ gaps: CompetitorGap[];+ /** False when too few of their pages were read to compare (at least two). */+ compared: boolean;+ /** Pages that couldn't be read. */+ unreadable: number;+ /** Why nothing was compared, when nothing was: the task is left to a person. */+ reason: 'no_prompts' | 'none_cited' | 'unreadable' | null;+}++const REASONS = ['no_prompts', 'none_cited', 'unreadable'] as const;++const count = (value: unknown) =>+ typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;+const strings = (value: unknown) =>+ Array.isArray(value) ? value.filter((v): v is string => typeof v === 'string' && v !== '') : [];++function pageOf(value: unknown): CitedPageRead | null {+ if (!value || typeof value !== 'object') return null;+ const p = value as Record<string, unknown>;+ if (typeof p.url !== 'string' || !/^https?:\/\//i.test(p.url)) return null;+ return {+ url: p.url,+ domain: typeof p.domain === 'string' ? p.domain : null,+ cited: count(p.cited),+ words: typeof p.words === 'number' && Number.isFinite(p.words) ? p.words : null,+ passes: strings(p.passes),+ };+}++/** The task's output read defensively; null when it isn't this task's. */+export function parseCompetitorFindings(output: unknown): CompetitorFindings | null {+ if (!output || typeof output !== 'object') return null;+ const o = output as Record<string, unknown>;+ if (!Array.isArray(o.competitorPages) || !Array.isArray(o.gaps)) return null;+ const yourPage = pageOf(o.yourPage);+ return {+ competitorPages: o.competitorPages.map(pageOf).filter((p): p is CitedPageRead => p !== null),+ yourPage,+ yourPageStatus: yourPage+ ? 'read'+ : o.yourPageStatus === 'unreadable'+ ? 'unreadable'+ : 'not_cited',+ gaps: o.gaps.flatMap((value) => {+ const g = (value ?? {}) as Record<string, unknown>;+ return typeof g.key === 'string' && g.key && count(g.of) > 0+ ? [+ {+ key: g.key,+ label: typeof g.label === 'string' && g.label ? g.label : g.key,+ competitors: count(g.competitors),+ of: count(g.of),+ },+ ]+ : [];+ }),+ compared: o.compared !== false,+ unreadable: count(o.unreadable),+ reason: (REASONS as readonly unknown[]).includes(o.reason)+ ? (o.reason as CompetitorFindings['reason'])+ : null,+ };+}diff --git a/web/src/lib/action-center/rows.ts b/web/src/lib/action-center/rows.tsindex 0ae01c9b3..9b0597b24 100644--- a/web/src/lib/action-center/rows.ts+++ b/web/src/lib/action-center/rows.ts@@ -19,6 +19,7 @@ import {withEntityCounts,type EntityCountRow,} from '@/lib/action-center/entity-counts';+import { COMPETITOR_TASK_KEY, parseCompetitorFindings } from './competitor-findings';/*** Action Center rows → the shapes the dashboard reads, shared by its server@@ -49,7 +50,7 @@ export const ACTION_COLUMNS ='id, action_no, category, kind, impact, status, payload, kpi_keys, assignee_id, due_date, created_at, updated_at, priority_score, priority_level, priority_reason, priority_updated_at';export const TASK_COLUMNS =- 'id, position, task_key, title, status, skip_reason, title_params, depends_on, details';+ 'id, position, task_key, title, status, skip_reason, title_params, depends_on, details, output';export const EVENT_COLUMNS = 'id, event, data, actor_id, created_at';@@ -104,6 +105,9 @@ export function taskFromRow(task: Record<string, unknown>): ActionTask {dependsOn: (task.depends_on ?? []) as string[],skipReason: (task.skip_reason as string | null) ?? null,details: parseTaskDetails(task.details),+ // What Analyze competitor content found, once it ran (learning C1).+ competitorFindings:+ task.task_key === COMPETITOR_TASK_KEY ? parseCompetitorFindings(task.output) : null,};}diff --git a/web/src/lib/actions/action-center.ts b/web/src/lib/actions/action-center.tsindex 30b6f076f..30fd40665 100644--- a/web/src/lib/actions/action-center.ts+++ b/web/src/lib/actions/action-center.ts@@ -60,6 +60,7 @@ import {type TaskDetailsEdit,} from '@/lib/action-center/task-details';import type { PriorityLevel, PriorityReason } from '@/lib/action-center/priority';+import type { CompetitorFindings } from '@/lib/action-center/competitor-findings';import { assertWritable } from '@/lib/subscription-guard';export interface ActionAssignee {@@ -175,6 +176,8 @@ export interface ActionTask {* platform and evidence (PROMPT-004). Null when it carries nothing.*/details: ActionTaskDetails | null;+ /** What Analyze competitor content found, once it ran (learning C1). */+ competitorFindings?: CompetitorFindings | null;}export interface ActionEvent {