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): move the agent's waiting page while it works (#1523)

Cihanf542b94669d7
diff --git a/web/messages/en.json b/web/messages/en.json
index 2d421f035..524006bc0 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -3770,6 +3770,20 @@
"write": "Rewriting the page",
"review": "Opens here beside your page to compare"
}
+ },
+ "doing": {
+ "answerFirst": "Answering the page's main question first",
+ "outline": "Giving each section one question to answer",
+ "missing": "Answering questions the page misses",
+ "quoted": "Leaving passages AI quotes as they are",
+ "length": "Keeping the page near its target length",
+ "kept": "Keeping quoted passages, tables and images",
+ "voice": "Keeping the page's facts and voice",
+ "rules": "Keeping to {count, plural, one {# rule} other {# rules}}",
+ "rulesAny": "Keeping to the rules",
+ "sources": "Drawing on {count, plural, one {# source} other {# sources}}",
+ "sourcesAny": "Drawing on your sources",
+ "placeholders": "Adding a [placeholder] for facts it lacks"
}
},
"agentFailed": {
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 690f55904..8c3ed6c3e 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
@@ -102,7 +102,7 @@ function AgentIcon({ working, slow }: { working: boolean; slow: boolean }) {
);
}
-function AgentTile({
+export function AgentTile({
tone,
count,
}: {
@@ -162,11 +162,34 @@ function PersonTile() {
);
}
+/**
+ * A light that passes over the step under way, again and again: the agent's
+ * card's sweep, faint enough for a chip. Gone with reduced motion.
+ */
+export function StepSweep() {
+ return (
+ <span
+ aria-hidden
+ className="pointer-events-none absolute inset-0 animate-agent-sweep bg-[linear-gradient(110deg,transparent_30%,color-mix(in_oklab,var(--foreground)_9%,transparent)_50%,transparent_70%)] bg-[length:250%_100%] [animation-duration:2.2s] motion-reduce:hidden"
+ />
+ );
+}
+
/**
* A run's steps as chips (CE-027/035), named by the data they use: the ones
* done in green with a check, the one under way in full, the rest muted.
*/
-export function RunSteps({ run }: { run: AgentRun }) {
+export function RunSteps({
+ run,
+ moving = false,
+}: {
+ run: AgentRun;
+ /**
+ * The step under way moves (a sweep and the agent's dots), where nothing
+ * else on the page says the agent works (CE-026: its waiting page).
+ */
+ moving?: boolean;
+}) {
const t = useTranslations('contentEditor.editor.agentCard.steps');
const shown = shownSteps(run);
return (
@@ -187,11 +210,14 @@ export function RunSteps({ run }: { run: AgentRun }) {
done &&
'border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300',
now && 'bg-background font-medium text-foreground',
+ now && moving && 'relative overflow-hidden',
!done && !now && 'border-dashed text-muted-foreground',
)}
>
+ {now && moving && <StepSweep />}
{done && <Check aria-hidden className="h-3 w-3 shrink-0" />}
{t(key, count === undefined ? {} : { count })}
+ {now && moving && <WorkingDots className="ml-0.5" />}
</span>
</li>
);
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx
index 78091adf0..7af49b0b7 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-writing.tsx
@@ -3,14 +3,15 @@
import { useEffect, useState } from 'react';
import { useNow, useTranslations } from 'next-intl';
import { toast } from 'sonner';
-import { ArrowLeft, Bot, Check, Circle } from 'lucide-react';
+import { ArrowLeft, Check, Circle } from 'lucide-react';
import { Link } from '@/i18n/navigation';
import { Button } from '@/components/ui/button';
import { buttonVariants } from '@/components/ui/button-variants';
import { stopAgentRun } from '@/lib/content/agent-runs-client';
+import type { AgentRun } from '@/lib/content/agent-runs';
import { CONTENT_LIBRARY_PATH, type DraftMethod } from '@/lib/content/drafts';
import { cn } from '@/lib/utils';
-import { RunSteps } from './_agent-card';
+import { AgentTile, RunSteps, StepSweep } from './_agent-card';
import { WorkingDots } from './_working-dots';
import { useAgentRun } from './_use-agent-run';
@@ -36,6 +37,32 @@ const SLOW_AFTER_S = 120;
/** The runs this page waits on: a new page, or the whole page rewritten. */
const WRITING_RUNS = ['write', 'rewrite'] as const;
+/**
+ * What the agent does while it writes, as its prompt asks it
+ * (content-writer.js WRITE_SYSTEM_PROMPT and SUGGEST_SYSTEM_PROMPT,
+ * content-rewrite.js), one line at a time: the wait reads as the work going
+ * on, never as progress made up.
+ */
+const DOING = {
+ create: ['answerFirst', 'outline', 'rules', 'sources', 'placeholders'],
+ optimize: ['missing', 'quoted', 'rules', 'sources', 'placeholders'],
+ rewrite: ['rules', 'length', 'kept', 'voice', 'sources', 'placeholders'],
+} as const;
+/** Seconds each line stays. */
+const DOING_S = 4;
+
+/** A page's lines, drawn in one after another while it is written: [kind, width %]. */
+const PAGE_LINES = [
+ ['h', 55],
+ ['p', 96],
+ ['p', 88],
+ ['p', 64],
+ ['h', 40],
+ ['p', 92],
+ ['p', 84],
+ ['p', 52],
+] as const;
+
/** The seconds since the agent started, null when the start isn't known. */
function elapsedSeconds(since: string | null, now: Date): number | null {
const start = since ? new Date(since).getTime() : NaN;
@@ -47,13 +74,77 @@ function elapsedSeconds(since: string | null, now: Date): number | null {
const clock = (seconds: number) =>
`${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
+/**
+ * The line on what the agent does now, from DOING, with the counts its run
+ * read (its rules, its sources); a new one every DOING_S seconds.
+ */
+function DoingLine({
+ mode,
+ run,
+ seconds,
+}: {
+ mode: keyof typeof DOING;
+ run: AgentRun | null;
+ seconds: number | null;
+}) {
+ const t = useTranslations('contentEditor.editor.agentWriting.doing');
+ const counted = (key: 'read_rules' | 'gather_sources') =>
+ run?.steps.find((step) => step.key === key)?.count ?? null;
+ const counts = { rules: counted('read_rules'), sources: counted('gather_sources') };
+ // None read (the step's chip is left out too): not a line to say.
+ const lines = DOING[mode].filter(
+ (line) => (line !== 'rules' && line !== 'sources') || counts[line] !== 0,
+ );
+ const line = lines[Math.floor((seconds ?? 0) / DOING_S) % lines.length];
+ const said = (): string => {
+ if (line !== 'rules' && line !== 'sources') return t(line);
+ const count = counts[line];
+ return count === null ? t(`${line}Any`) : t(line, { count });
+ };
+ return (
+ // Hidden from screen readers, as the clock: a status that reads out every few seconds.
+ <p aria-hidden className="min-w-0 flex-1 text-xs text-muted-foreground">
+ <span
+ key={line}
+ className="block truncate animate-in duration-500 fade-in slide-in-from-bottom-1 motion-reduce:animate-none"
+ >
+ {said()}
+ </span>
+ </p>
+ );
+}
+
+/**
+ * A faint page whose lines are drawn in, one after another, while the agent
+ * writes it. Still, and whole, with reduced motion.
+ */
+function PageFilling() {
+ return (
+ <div aria-hidden className="mt-6 w-full max-w-sm space-y-2 rounded-xl border border-dashed p-4">
+ {PAGE_LINES.map(([kind, width], i) => (
+ <span
+ key={i}
+ className={cn(
+ 'block origin-left animate-agent-fill rounded-full motion-reduce:animate-none',
+ kind === 'h'
+ ? 'h-2.5 bg-muted-foreground/25 [&:not(:first-child)]:mt-4'
+ : 'h-1.5 bg-muted-foreground/15',
+ )}
+ style={{ width: `${width}%`, animationDelay: `${i * 0.45}s` }}
+ />
+ ))}
+ </div>
+ );
+}
+
/**
* The draft while the Content Agent writes it (CE-015): nothing to edit yet,
* so the page shows the agent at work, step by step as Chat shows its tools,
* with the time it has taken, and says when that's longer than usual. The
* editor opens on what it wrote. Once its run reads (v1.1 CE-027/035), its
* real steps, named by the data they use, and Stop, which leaves the page as
- * it was.
+ * it was. It moves while it waits (CE-026): the agent's tile, a sweep on the
+ * step under way, a line on what it does, and the page drawn in.
*/
export function AgentWriting({
draftId,
@@ -77,6 +168,7 @@ export function AgentWriting({
}) {
const t = useTranslations('contentEditor.editor');
const seconds = elapsedSeconds(since, useNow({ updateInterval: 1000 }));
+ const mode = rewrite ? 'rewrite' : method;
const live = useAgentRun(draftId, true, WRITING_RUNS);
const [stopping, setStopping] = useState(false);
// The last run read stays until the editor opens: the fixed list never
@@ -123,60 +215,68 @@ export function AgentWriting({
</header>
<div className="flex flex-1 flex-col items-center justify-center px-6">
<div role="status" className="w-full max-w-sm space-y-4">
- <div className="flex items-center gap-2.5">
- <span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted">
- <Bot aria-hidden className="h-4 w-4" />
- </span>
+ <div className="flex items-center gap-3">
+ <AgentTile tone="working" count={0} />
<p className="text-sm font-medium">{t('agentWriting.title')}</p>
</div>
{run ? (
<div className="space-y-2 rounded-xl border bg-card px-4 py-3.5">
- <RunSteps run={run} />
- {seconds !== null && (
- <p aria-hidden className="text-xs text-muted-foreground tabular-nums">
- {clock(seconds)}
- </p>
- )}
+ <RunSteps run={run} moving />
+ <div className="flex items-center gap-3 border-t pt-2.5">
+ <DoingLine mode={mode} run={run} seconds={seconds} />
+ {seconds !== null && (
+ <p aria-hidden className="shrink-0 text-xs text-muted-foreground tabular-nums">
+ {clock(seconds)}
+ </p>
+ )}
+ </div>
</div>
) : (
- <ol className="space-y-2.5 rounded-xl border bg-card px-4 py-3.5">
- {STEPS.map((step, i) => (
- <li
- key={step}
- aria-current={i === WRITING ? 'step' : undefined}
- className={cn(
- 'flex items-center gap-2.5 text-sm',
- i > WRITING && 'text-muted-foreground',
- )}
- >
- {i < WRITING ? (
- <Check
- aria-hidden
- className="h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400"
- />
- ) : i === WRITING ? (
- // No spinning ring (v1.1 §2.4): the agent's dots.
- <span className="flex h-4 w-4 shrink-0 items-center justify-center">
- <WorkingDots className="ml-0" />
+ <div className="space-y-2.5 rounded-xl border bg-card px-4 py-3.5">
+ <ol className="space-y-2.5">
+ {STEPS.map((step, i) => (
+ <li
+ key={step}
+ aria-current={i === WRITING ? 'step' : undefined}
+ className={cn(
+ 'flex items-center gap-2.5 text-sm',
+ i === WRITING && 'relative -mx-2 -my-1 overflow-hidden rounded-md px-2 py-1',
+ i > WRITING && 'text-muted-foreground',
+ )}
+ >
+ {i === WRITING && <StepSweep />}
+ {i < WRITING ? (
+ <Check
+ aria-hidden
+ className="h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400"
+ />
+ ) : i === WRITING ? (
+ // No spinning ring (v1.1 §2.4): the agent's dots.
+ <span className="flex h-4 w-4 shrink-0 items-center justify-center">
+ <WorkingDots className="ml-0" />
+ </span>
+ ) : (
+ <Circle aria-hidden className="h-4 w-4 shrink-0 text-muted-foreground/60" />
+ )}
+ <span className="min-w-0 flex-1">
+ {t(`agentWriting.steps.${mode}.${step}`)}
</span>
- ) : (
- <Circle aria-hidden className="h-4 w-4 shrink-0 text-muted-foreground/60" />
- )}
- <span className="min-w-0 flex-1">
- {t(`agentWriting.steps.${rewrite ? 'rewrite' : method}.${step}`)}
- </span>
- {/* Hidden from screen readers: a status that reads out every second. */}
- {i === WRITING && seconds !== null && (
- <span
- aria-hidden
- className="shrink-0 text-xs text-muted-foreground tabular-nums"
- >
- {clock(seconds)}
- </span>
- )}
- </li>
- ))}
- </ol>
+ {/* Hidden from screen readers: a status that reads out every second. */}
+ {i === WRITING && seconds !== null && (
+ <span
+ aria-hidden
+ className="shrink-0 text-xs text-muted-foreground tabular-nums"
+ >
+ {clock(seconds)}
+ </span>
+ )}
+ </li>
+ ))}
+ </ol>
+ <div className="border-t pt-2.5">
+ <DoingLine mode={mode} run={null} seconds={seconds} />
+ </div>
+ </div>
)}
<p className="text-xs text-muted-foreground">
{seconds !== null && seconds >= SLOW_AFTER_S ? (
@@ -195,6 +295,7 @@ export function AgentWriting({
</Button>
</div>
)}
+ <PageFilling />
</div>
</>
);
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.tsx
index 262fa5849..d10db099e 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
@@ -852,6 +852,129 @@ describe('the content editor', () => {
expect(getContentDraft.mock.calls.length).toBe(reads + 1);
});
+ it('moves while it works, with a line on what it does, and stands still with reduced motion (CE-026)', async () => {
+ vi.useFakeTimers({
+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],
+ });
+ try {
+ getContentDraft.mockResolvedValue(
+ draft({
+ status: 'draft',
+ method: 'create',
+ agentState: 'writing',
+ agentSince: new Date().toISOString(),
+ }),
+ );
+ readAgentRun.mockResolvedValue({
+ id: 'r1',
+ kind: 'write',
+ steps: [
+ { key: 'read_rules', count: 9 },
+ { key: 'gather_sources', count: 52 },
+ { key: 'write_page', count: null },
+ { key: 'check_sources', count: null },
+ ],
+ step: 2,
+ startedAt: new Date().toISOString(),
+ finishedAt: null,
+ stoppedAt: null,
+ outcome: null,
+ });
+ await renderPage();
+ await act(async () => {});
+ const status = container.querySelector('[role="status"]')!;
+ // The agent's tile breathes, the step under way has its sweep and dots.
+ expect(status.querySelector('.animate-agent-breathe')).not.toBeNull();
+ const now = status.querySelector('[aria-current="step"]')!;
+ expect(now.textContent).toBe('Writing the page');
+ expect(now.querySelector('.animate-agent-sweep')).not.toBeNull();
+ expect(now.querySelector('.animate-agent-dot')).not.toBeNull();
+ // One line at a time on what it does, with what its run read.
+ expect(status.textContent).toContain("Answering the page's main question first");
+ await act(async () => void (await vi.advanceTimersByTimeAsync(4_000)));
+ expect(status.textContent).toContain('Giving each section one question to answer');
+ expect(status.textContent).not.toContain("Answering the page's main question first");
+ await act(async () => void (await vi.advanceTimersByTimeAsync(4_000)));
+ expect(status.textContent).toContain('Keeping to 9 rules');
+ await act(async () => void (await vi.advanceTimersByTimeAsync(4_000)));
+ expect(status.textContent).toContain('Drawing on 52 sources');
+ // The page drawn in, line by line.
+ expect(container.querySelectorAll('.animate-agent-fill').length).toBeGreaterThan(0);
+ // No spinning ring, and all of it still with reduced motion.
+ expect(container.querySelector('.animate-spin')).toBeNull();
+ const moving = [...container.querySelectorAll('[class*="animate-agent"], .animate-in')];
+ expect(
+ moving.every((el) =>
+ /motion-reduce:(animate-none|hidden)/.test(el.getAttribute('class')!),
+ ),
+ ).toBe(true);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it('says what it does on a live page', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
+ try {
+ getContentDraft.mockResolvedValue(
+ draft({
+ status: 'draft',
+ agentState: 'writing',
+ agentSince: new Date(Date.now() - 4_000).toISOString(),
+ }),
+ );
+ await renderPage();
+ const status = container.querySelector('[role="status"]')!;
+ // Optimize, its second line: the passages it keeps.
+ expect(status.textContent).toContain('Leaving passages AI quotes as they are');
+ expect(status.querySelector('[aria-current="step"] .animate-agent-sweep')).not.toBeNull();
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
+ it('says nothing of rules or sources its run read none of', async () => {
+ vi.useFakeTimers({
+ toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'Date'],
+ });
+ try {
+ getContentDraft.mockResolvedValue(
+ draft({
+ status: 'draft',
+ method: 'create',
+ agentState: 'writing',
+ agentSince: new Date().toISOString(),
+ }),
+ );
+ readAgentRun.mockResolvedValue({
+ id: 'r1',
+ kind: 'write',
+ steps: [
+ { key: 'read_rules', count: 0 },
+ { key: 'gather_sources', count: 0 },
+ { key: 'write_page', count: null },
+ ],
+ step: 2,
+ startedAt: new Date().toISOString(),
+ finishedAt: null,
+ stoppedAt: null,
+ outcome: null,
+ });
+ await renderPage();
+ await act(async () => {});
+ const status = container.querySelector('[role="status"]')!;
+ const said: string[] = [];
+ for (let i = 0; i < 5; i++) {
+ said.push(status.textContent!);
+ await act(async () => void (await vi.advanceTimersByTimeAsync(4_000)));
+ }
+ expect(said.join(' ')).toContain('Adding a [placeholder] for facts it lacks');
+ expect(said.join(' ')).not.toMatch(/Keeping to|Drawing on/);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it('reads the draft at once when its run ends, its steps shown till then', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
try {
diff --git a/web/src/app/globals.css b/web/src/app/globals.css
index 430f3207b..5dd3bfcf7 100644
--- a/web/src/app/globals.css
+++ b/web/src/app/globals.css
@@ -156,9 +156,10 @@
}
/*
- * The Content Agent card's motion (Content Editor v1.1, CE-026): subtle, and
- * never a rotating ring. Each element that moves also takes
- * motion-reduce:animate-none, so all of it stops with reduced motion.
+ * The Content Agent card's motion (Content Editor v1.1, CE-026), and its
+ * waiting page's: subtle, and never a rotating ring. Each element that moves
+ * also takes motion-reduce:animate-none, so all of it stops with reduced
+ * motion.
*/
@theme {
--animate-agent-ring: agent-ring 2.2s ease-out infinite;
@@ -170,6 +171,7 @@
--animate-agent-look: agent-look 1.2s ease-in-out infinite;
--animate-agent-dot: agent-dot 1.2s infinite;
--animate-agent-slide: agent-slide 1.4s ease-in-out infinite;
+ --animate-agent-fill: agent-fill 6s ease-out infinite both;
@keyframes agent-ring {
0% {
@@ -248,4 +250,23 @@
transform: translateX(340%);
}
}
+ /* A line of the page drawn in, kept a while, then gone for the next pass. */
+ @keyframes agent-fill {
+ 0% {
+ transform: scaleX(0);
+ opacity: 0;
+ }
+ 10% {
+ opacity: 1;
+ }
+ 30%,
+ 85% {
+ transform: scaleX(1);
+ opacity: 1;
+ }
+ 100% {
+ transform: scaleX(1);
+ opacity: 0;
+ }
+ }
}