Skip to content

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.

fix(content): head the agent card with the result waiting for a decision, and say how many placeholders it leaves (#1517)

Cihan043011bd3695
diff --git a/web/messages/en.json b/web/messages/en.json
index 8f10df362..947179c51 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -3803,6 +3803,7 @@
}
},
"agentCard": {
+ "placeholders": "{count, plural, one {# placeholder} other {# placeholders}} to fill",
"waiting": "{count, plural, one {Content Agent has # suggestion for you} other {Content Agent has # suggestions for you}}",
"gain": "Rules {met, number} → {after, number} of {total, number}",
"review": "Review",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.test.tsx
index 94aadee92..023570e0b 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.test.tsx
@@ -210,7 +210,7 @@ describe('AgentCard', () => {
// Working: the run, not the step.
await render([], true, { next: step });
expect(card.textContent).toBe('Content Agent is working');
- // A rewrite to decide: still under the step, with its own buttons.
+ // A rewrite to decide heads with what it is, not the step after it, with its own buttons.
await render(
[
suggestion({
@@ -223,13 +223,48 @@ describe('AgentCard', () => {
false,
{ next: step },
);
- expect(card.textContent).toContain('Next · Shorten to your Length');
+ expect(card.textContent).not.toContain('Next · Shorten to your Length');
expect(card.textContent).toContain(
- 'Last run: Content Agent rewrote the page to its rules · 37 → 12 characters · cut to the Length',
+ 'Content Agent rewrote the page to its rules37 → 12 characters · cut to the Length',
);
expect(buttons()).toEqual(['Compare', 'Reject', 'Accept']);
});
+ it('says how many placeholders the result leaves to fill', async () => {
+ const page = suggestion({
+ kind: 'page',
+ beforeHtml: '<h1>Old</h1><p>Teams cut churn by [figure, source].</p>',
+ afterText:
+ '<h1>New</h1><p>Teams cut churn by [figure, source].</p><p>[name of a real person] said so in [year].</p>',
+ reason: 'answered each heading first',
+ });
+ await render([page], false);
+ // Two new: the one the page had isn't the run's.
+ expect(container.textContent).toContain('answered each heading first · 2 placeholders to fill');
+ // A list the agent wrote without paragraphs in its items: read by their words.
+ await render(
+ [
+ suggestion({
+ kind: 'page',
+ beforeHtml: '<h1>Old</h1><ul><li><p>Churn fell [figure, source].</p></li></ul>',
+ afterText:
+ '<h1>New</h1><ul><li>Churn fell [figure, source].</li></ul><p>Since [year].</p>',
+ reason: 'kept the list',
+ }),
+ ],
+ false,
+ );
+ expect(container.textContent).toContain('kept the list · 1 placeholder to fill');
+ await render(
+ [
+ suggestion({ afterText: 'look at [figure, source]' }),
+ suggestion({ id: 's2', beforeText: 'old', afterText: 'new' }),
+ ],
+ false,
+ );
+ expect(container.textContent).toContain('1 placeholder to fill');
+ });
+
it('reads a rewrite against the Length, not the agent’s say, and says what it kept', async () => {
const page = suggestion({
kind: 'page',
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.tsx
index d4354eb9a..cdb81ddef 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-card.tsx
@@ -1,6 +1,6 @@
'use client';
-import { useId, useState } from 'react';
+import { useId, useMemo, useState } from 'react';
import { useLocale, useTranslations } from 'next-intl';
import { Check, ChevronRight, User, X } from 'lucide-react';
import { Link } from '@/i18n/navigation';
@@ -14,6 +14,7 @@ import {
import { shownSteps, stepMessage, type AgentRun } from '@/lib/content/agent-runs';
import { cn } from '@/lib/utils';
import { PageCompareDialog, pageCharacters } from './_page-rewrite';
+import { PLACEHOLDER, pagePlaceholders } from '@/lib/content/placeholders';
import { WorkingDots } from './_working-dots';
/**
@@ -278,6 +279,20 @@ export function AgentCard({
const tRewrite = useTranslations('contentEditor.editor.rewrite');
const [comparing, setComparing] = useState(false);
const page = suggestions.find((s) => s.kind === 'page') ?? null;
+ // The placeholders an open rewrite adds, for the person to fill: read once
+ // a rewrite, not on every key the page takes.
+ const pageOpen = page?.status === 'open';
+ const pageLeft = useMemo(
+ () =>
+ pageOpen && page
+ ? Math.max(
+ 0,
+ pagePlaceholders(page.afterText).count - pagePlaceholders(page.beforeHtml ?? '').count,
+ )
+ : 0,
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- the rewrite's two pages, not the object
+ [pageOpen, page?.afterText, page?.beforeHtml],
+ );
const { open, accepted } = suggestionCounts(suggestions);
const openOnes = suggestions.filter((s) => s.status === 'open');
const action = suggestions.find((s) => s.actionId && s.actionNo !== null);
@@ -393,6 +408,7 @@ export function AgentCard({
) : (
page.reason
)}
+ {pageLeft > 0 && ` · ${t('placeholders', { count: pageLeft })}`}
{builtFrom}
</>
) : page.status === 'accepted' && stillOpen > 0 ? (
@@ -400,10 +416,22 @@ export function AgentCard({
) : null;
} else if (open > 0) {
title = t('waiting', { count: open });
+ // The placeholders its changes add, for the person to fill once accepted.
+ const batchLeft = openOnes.reduce(
+ (n, s) =>
+ n +
+ Math.max(
+ 0,
+ (s.afterText.match(PLACEHOLDER) ?? []).length -
+ (s.beforeText.match(PLACEHOLDER) ?? []).length,
+ ),
+ 0,
+ );
line = (
<>
{sentence(openOnes[0]?.reason ?? '', locale)}
{openOnes.length > 1 && ` · ${t('more', { count: openOnes.length - 1 })}`}
+ {batchLeft > 0 && ` · ${t('placeholders', { count: batchLeft })}`}
{after > rules.met && (
<>
{' · '}
@@ -443,8 +471,11 @@ export function AgentCard({
}
// With the basket (Next step spec §3), the card heads with the step and
- // who takes it; what the agent left is its last run, under it.
- const stepHead = !working && next?.title ? next : null;
+ // who takes it; what the agent left is its last run, under it. Not while
+ // the agent's result waits for a decision: it heads with what it is
+ // (editor test 2026-10-25: "Next · Shorten…" over a rewrite read as
+ // another agent).
+ const stepHead = nextShown && next?.title ? next : null;
let lastRun: React.ReactNode = null;
if (stepHead) {
const run = title;
diff --git a/web/src/lib/content/placeholders.test.ts b/web/src/lib/content/placeholders.test.ts
index 34082aa41..a5968d8f8 100644
--- a/web/src/lib/content/placeholders.test.ts
+++ b/web/src/lib/content/placeholders.test.ts
@@ -35,4 +35,11 @@ describe('pagePlaceholders', () => {
),
).toEqual({ count: 2 });
});
+ it('reads a list item written without a paragraph by its own words, once', () => {
+ expect(
+ pagePlaceholders(
+ '<ul><li>Churn fell [figure, source].<ul><li>Then [year].</li></ul></li><li><p>[price]</p></li></ul>',
+ ).count,
+ ).toBe(3);
+ });
});
diff --git a/web/src/lib/content/placeholders.ts b/web/src/lib/content/placeholders.ts
index a175bb1eb..540cf5952 100644
--- a/web/src/lib/content/placeholders.ts
+++ b/web/src/lib/content/placeholders.ts
@@ -31,16 +31,31 @@ export interface PagePlaceholders {
count: number;
}
+/** Elements inside a line of text: what a list item's own words are made of. */
+const INLINE = /^(A|STRONG|EM|B|I|U|S|SPAN|CODE|MARK|SUB|SUP|SMALL|BR)$/;
+
+/** A list item's own words: its text and inline elements, not the blocks inside it. */
+function itemOwnText(li: Element): string {
+ let text = '';
+ for (const node of li.childNodes) {
+ if (node.nodeType === Node.TEXT_NODE) text += node.textContent ?? '';
+ else if (node instanceof Element && INLINE.test(node.tagName)) text += node.textContent ?? '';
+ }
+ return text;
+}
+
/**
* The page's placeholders. The editor keeps every line of text in a
* paragraph or a heading (in lists, quotes and tables too), so each is read
- * once there.
+ * once there; a list item written without one (an agent's rewrite) is read
+ * by its own words.
*/
export function pagePlaceholders(html: string): PagePlaceholders {
const doc = new DOMParser().parseFromString(html, 'text/html');
let count = 0;
- for (const el of doc.body.querySelectorAll('p, h1, h2, h3, h4, h5, h6')) {
- count += (el.textContent ?? '').match(placeholderIn(el.tagName !== 'P'))?.length ?? 0;
+ for (const el of doc.body.querySelectorAll('p, h1, h2, h3, h4, h5, h6, li')) {
+ const text = el.tagName === 'LI' ? itemOwnText(el) : (el.textContent ?? '');
+ count += text.match(placeholderIn(/^H\d$/.test(el.tagName)))?.length ?? 0;
}
return { count };
}