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.

feat(content): say when an agent run stops at its most, and when Length can't fit the rules (#1384)

Cihanc439c9e13408
diff --git a/web/messages/en.json b/web/messages/en.json
index 203163b9c..42831e099 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -3597,6 +3597,7 @@
"fromAction": "from Action AC-{no}",
"decided": "{accepted} accepted · {rejected} rejected",
"rulesOpen": "{count, plural, one {# rule still open} other {# rules still open}}",
+ "runMax": "a run makes at most {max} changes: run it again for the rest",
"acceptAll": "Accept all",
"rejectAll": "Reject all",
"undoAll": "Undo all",
@@ -3620,6 +3621,7 @@
"fixRules": "Apply rules with Agent",
"fixing": "Content Agent is working…",
"fixed": "{count, plural, one {Content Agent suggested # change} other {Content Agent suggested # changes}} · review them in the page",
+ "fixedMax": "Content Agent suggested {count} changes, the most one run makes · review them, then run it again for the rules still open",
"nothingToFix": "Content Agent found nothing it could change without new facts.",
"notForAgent": "Content Agent doesn't change heading levels: make the extra H1s H2s in the toolbar.",
"decideFirst": "Accept or reject the open suggestions first.",
@@ -4084,6 +4086,7 @@
"agentFix": "Apply rules with Agent",
"agentFixing": "Content Agent is working…",
"agentFixHint": "Content Agent suggests changes for the rules not met yet, for you to review in the page",
+ "lengthConflict": "The fan-out H2s, FAQ questions and summary these rules still ask for take about {need, number} characters, more than Length allows (up to {max, number}). Raise Length, or ask for fewer.",
"fixTrace": "Fix",
"fixTraceHint": "Content Agent rewrites only these phrases, for you to review",
"agent": {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-bar.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-bar.tsx
index cfdc9c49f..29d5cb6a9 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-bar.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_agent-bar.tsx
@@ -4,14 +4,15 @@ import { useTranslations } from 'next-intl';
import { Bot, Loader2, X } from 'lucide-react';
import { Link } from '@/i18n/navigation';
import { Button } from '@/components/ui/button';
-import { suggestionCounts, type DraftSuggestion } from '@/lib/content/suggestions';
+import { AGENT_RUN_MAX, suggestionCounts, type DraftSuggestion } from '@/lib/content/suggestions';
/**
* The agent bar over the page (CE-018): while an agent's suggestions are
* open, who left how many and from which action, with Reject all and Accept
* all (open ones only); once all are decided, how many were accepted and
* rejected and how many rules are still open, with Apply rules with
- * Agent for a new batch. Undo all brings every decided one back to review.
+ * Agent for a new batch (a full batch says a run stops there, so run it
+ * again). Undo all brings every decided one back to review.
*/
export function AgentBar({
suggestions,
@@ -68,6 +69,14 @@ export function AgentBar({
<span className="text-muted-foreground">
{' · '}
{t('rulesOpen', { count: rulesOpen })}
+ {/* A full run's batch may have stopped short of the rules still open
+ (an API batch can hold more, and says nothing of a run). */}
+ {suggestions.length === AGENT_RUN_MAX && (
+ <>
+ {' · '}
+ {t('runMax', { max: AGENT_RUN_MAX })}
+ </>
+ )}
</span>
)}
</span>
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.tsx
index 39247a9e4..6d6cd08cc 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
@@ -49,7 +49,11 @@ import {
type DraftExportFormat,
} from '@/lib/content/draft-export';
import type { DraftVersion } from '@/lib/content/history';
-import type { DraftSuggestion, SuggestionStatus } from '@/lib/content/suggestions';
+import {
+ AGENT_RUN_MAX,
+ type DraftSuggestion,
+ type SuggestionStatus,
+} from '@/lib/content/suggestions';
import {
cleanHtml,
formatHtmlSource,
@@ -558,6 +562,11 @@ export function DraftEditor({
};
const openSuggestions = suggestions.filter((s) => s.status === 'open').length;
+ // A full batch: the run stopped at its most, so it says to run it again.
+ const fixedMessage = (count: number) =>
+ count >= AGENT_RUN_MAX
+ ? t('suggestions.fixedMax', { count })
+ : t('suggestions.fixed', { count });
/**
* Fix open rules with agent: the page as it is now is saved, then the
* Content Agent reads it with the rules still open (or only the ones
@@ -619,9 +628,7 @@ export function DraftEditor({
setSuggestions(landed);
setBarClosed(false);
agentBeforeKept.current = false;
- toast.success(
- t('suggestions.fixed', { count: landed.filter((s) => s.status === 'open').length }),
- );
+ toast.success(fixedMessage(landed.filter((s) => s.status === 'open').length));
return;
}
if ('error' in result) {
@@ -641,7 +648,7 @@ export function DraftEditor({
setBarClosed(false);
// A new batch: History keeps the page again before its first change.
agentBeforeKept.current = false;
- toast.success(t('suggestions.fixed', { count: result.count }));
+ toast.success(fixedMessage(result.count));
} catch (err) {
console.error('Failed to run the Content Agent:', err);
toast.error(t('suggestions.fixErrors.failed'));
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.test.tsx
index d3ac794e6..27777effb 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.test.tsx
@@ -51,6 +51,7 @@ function state(
ready: true,
...rulesMet(checked),
length: 3000,
+ lengthConflict: null,
change,
pickSet,
addTextRules,
@@ -238,6 +239,23 @@ describe('the Rules tab', () => {
expect(container.querySelector('fieldset')!.disabled).toBe(false);
});
+ it('says under Length when the other rules can’t fit in it (C)', async () => {
+ await render(state());
+ expect(row('Length').querySelector('.text-amber-700')).toBeNull();
+ await render(state(undefined, { lengthConflict: { need: 2350, max: 1200 } }));
+ expect(row('Length').textContent).toContain(
+ 'The fan-out H2s, FAQ questions and summary these rules still ask for take about 2,350 characters, more than Length allows (up to 1,200). Raise Length, or ask for fewer.',
+ );
+ // Off, Length asks for nothing.
+ await render(
+ state(
+ { overrides: { length: { on: false } } },
+ { lengthConflict: { need: 2350, max: 1200 } },
+ ),
+ );
+ expect(row('Length').textContent).not.toContain('Raise Length');
+ });
+
it('shows Ansvisor’s set when a draft on My rules has none for its type', async () => {
await render(state(undefined, { source: 'mine', mineTypes: [] }));
const trigger = container.querySelector('[aria-label="Rule set"]')!;
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.tsx
index eb243fbfa..290f11bdf 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_rules-tab.tsx
@@ -181,6 +181,11 @@ export function RulesTab({
onChange={(change) => state.change(rule.key, change)}
agentFix={rule.key === 'aiTraces' ? agentFix : undefined}
onOpenSources={onOpenSources}
+ note={
+ rule.key === 'length' && state.lengthConflict
+ ? t('lengthConflict', state.lengthConflict)
+ : undefined
+ }
/>
))}
</ul>
@@ -359,6 +364,7 @@ function RuleRow({
onChange,
agentFix,
onOpenSources,
+ note,
}: {
rule: ActiveRule;
status: RuleStatus;
@@ -366,6 +372,8 @@ function RuleRow({
/** "Remove AI traces" offers Fix: the agent rewrites only those phrases. */
agentFix?: AgentFix;
onOpenSources?: () => void;
+ /** A warning under the rule: Length, when the other rules can't fit in it. */
+ note?: string;
}) {
const t = useTranslations('contentEditor.editor.rules');
const name = t(`names.${rule.key}`);
@@ -406,6 +414,9 @@ function RuleRow({
<RuleValue rule={rule} name={name} onCommit={(value) => onChange({ value })} />
</div>
)}
+ {note && rule.on && (
+ <p className="mt-1 pl-9 text-[11px] text-amber-700 dark:text-amber-400">{note}</p>
+ )}
</li>
);
}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-draft-rules.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-draft-rules.ts
index 2665217a0..c4e334f93 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-draft-rules.ts
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-draft-rules.ts
@@ -11,6 +11,7 @@ import {
checkRule,
draftRulesFit,
effectiveRules,
+ lengthConflict,
overridesForImport,
readPage,
ruleLength,
@@ -46,6 +47,8 @@ export interface DraftRulesState {
total: number;
/** The page length the rules ask for. */
length: number;
+ /** The sections and questions the rules ask for take more than Length allows. */
+ lengthConflict: { need: number; max: number } | null;
/** Turns a rule on or off, or gives it a value, for this draft. */
change: (key: string, change: { on?: boolean; value?: string }) => void;
/** Loads a set into the draft: a type's Ansvisor default, or the workspace's My rules for it. */
@@ -165,6 +168,10 @@ export function useDraftRules({
[rules, page, ctx],
);
const { met, total } = rulesMet(checked);
+ const conflict = useMemo(
+ () => lengthConflict(checked, ctx.fanouts.length),
+ [checked, ctx.fanouts.length],
+ );
/**
* Saves the latest change: one save at a time, so two quick changes can't
@@ -221,6 +228,7 @@ export function useDraftRules({
met,
total,
length: ruleLength(rules, setType),
+ lengthConflict: conflict,
change: (key, change) =>
edited({
overrides: { ...effective.overrides, [key]: { ...effective.overrides[key], ...change } },
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 4540faac1..b830ea863 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
@@ -1084,6 +1084,8 @@ describe('the content editor', () => {
'Accuracy is shown per team, each week, against closed revenue.Teams trust it.FAQDoes it work with custom stages? Yes, any stage.',
);
expect(bar()!.textContent).toMatch(/^2 accepted · 0 rejected · \d+ rules? still open/);
+ // Not a full run's batch: nothing about running it again.
+ expect(bar()!.textContent).not.toContain('a run makes at most');
await act(async () => barButton('Undo all').click());
await act(async () => {});
@@ -1939,6 +1941,31 @@ describe('the side panel', () => {
);
});
+ it('says a full batch is the most one run makes, to run it again (C)', async () => {
+ getContentDraft.mockResolvedValue(traced);
+ const full = Array.from({ length: 8 }, (_, i) => ({
+ ...agentSuggestion,
+ id: `n${i}`,
+ status: 'rejected' as const,
+ }));
+ getDraftSuggestions.mockResolvedValueOnce([]).mockResolvedValueOnce(full);
+ fixDraftRules.mockResolvedValue({ count: 8 });
+ await openRules();
+
+ await act(async () => panelButton('Apply rules with Agent').click());
+ await act(async () => {});
+
+ expect(toast.success).toHaveBeenCalledWith(
+ 'Content Agent suggested 8 changes, the most one run makes · review them, then run it again for the rules still open',
+ );
+ // Decided, with rules still open: the bar says to run it again.
+ expect(
+ container.querySelector('[role="region"][aria-label="Agent suggestions"]')!.textContent,
+ ).toMatch(
+ /^0 accepted · 8 rejected · \d+ rules? still open · a run makes at most 8 changes: run it again for the rest/,
+ );
+ });
+
// A timeout on the way back is not the agent failing: it may still finish.
it('shows the agent’s batch when it lands after the answer didn’t come back', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
diff --git a/web/src/lib/content/rules.test.ts b/web/src/lib/content/rules.test.ts
index d34f64e4c..df1842c55 100644
--- a/web/src/lib/content/rules.test.ts
+++ b/web/src/lib/content/rules.test.ts
@@ -12,6 +12,7 @@ import {
readPage,
ruleLength,
lengthWarns,
+ lengthConflict,
ruleSet,
rulesMet,
type ActiveRule,
@@ -538,6 +539,48 @@ describe('lengthWarns', () => {
});
});
+describe('lengthConflict', () => {
+ const statuses = (
+ overrides: Record<string, { on?: boolean; value?: string }>,
+ fanouts = ctx.fanouts,
+ ) =>
+ activeRules(ruleSet('blog_post'), { overrides }).map((r) => ({
+ rule: r,
+ status: checkRule(r, page('<h1>T</h1>', 100), { ...ctx, fanouts }),
+ }));
+
+ it('says when the sections, questions and summary asked for can’t fit in Length (C)', () => {
+ // 3 fan-out H2s (of 4 asked, 3 there are) × 200 + 5 FAQ questions × 150 + a summary, 100.
+ expect(lengthConflict(statuses({ length: { value: '1000' } }), 3)).toEqual({
+ need: 1_450,
+ max: 1_200,
+ });
+ expect(lengthConflict(statuses({ length: { value: '1500' } }), 3)).toBeNull();
+ expect(lengthConflict(statuses({}), 3)).toBeNull();
+ });
+
+ it('counts only the rules on and still open, and asks nothing of fan-outs there aren’t', () => {
+ // FAQ off: the 3 fan-out questions still need a FAQ.
+ expect(
+ lengthConflict(statuses({ length: { value: '800' }, faq: { on: false } }), 3)?.need,
+ ).toBe(600 + 450 + 100);
+ // No fan-outs: no fan-out H2s or fan-out questions to fit.
+ expect(lengthConflict(statuses({ length: { value: '600' } }, []), 0)?.need).toBe(750 + 100);
+ expect(
+ lengthConflict(statuses({ length: { value: '50' }, faq: { on: false } }, []), 0)?.need,
+ ).toBe(100);
+ // Length off asks for no length.
+ expect(lengthConflict(statuses({ length: { on: false, value: '500' } }), 3)).toBeNull();
+ // A page that meets them all shows they fit.
+ const met = statuses({ length: { value: '1000' } }).map((s) =>
+ ['fanoutH2', 'faq', 'fanoutFaq', 'summary'].includes(s.rule.key)
+ ? { ...s, status: { state: 'ok' as const } }
+ : s,
+ );
+ expect(lengthConflict(met, 3)).toBeNull();
+ });
+});
+
describe('My rules and text rules', () => {
const mine = {
overrides: { sentence: { value: '120' } },
diff --git a/web/src/lib/content/rules.ts b/web/src/lib/content/rules.ts
index 2281b11fa..f5769a2d4 100644
--- a/web/src/lib/content/rules.ts
+++ b/web/src/lib/content/rules.ts
@@ -924,6 +924,50 @@ export function lengthWarns(statuses: { rule: ActiveRule; status: RuleStatus }[]
);
}
+/**
+ * The least text, in characters, a part the rules ask for takes: a heading
+ * with a two-sentence answer under it, a question with a one-sentence
+ * answer, a summary of a sentence or two. Kept low on purpose, so a page
+ * told they don't fit really can't hold them.
+ */
+const LEAST_SECTION = 200;
+const LEAST_QUESTION = 150;
+const LEAST_SUMMARY = 100;
+
+/**
+ * Rules that can't both be met (Content Agent rule gaps, C): the fan-out
+ * sections, FAQ questions and summary the rules in effect still ask for, at
+ * their least, against the most text Length allows. Null when they fit,
+ * when the page already meets them all, or when Length is off. Rules the
+ * page can't check yet (no fan-outs) ask for nothing, and a fan-out rule
+ * asks for no more fan-outs than there are.
+ */
+export function lengthConflict(
+ statuses: { rule: ActiveRule; status: RuleStatus }[],
+ fanouts: number,
+): { need: number; max: number } | null {
+ const counted: RuleStatus[] = [];
+ const asked = (key: string) => {
+ const found = statuses.find((s) => s.rule.key === key);
+ if (!found?.rule.on || found.status.state === 'info') return 0;
+ const n = Number(found.rule.current);
+ if (!Number.isFinite(n) || n <= 0) return 0;
+ counted.push(found.status);
+ return n;
+ };
+ const length = statuses.find((s) => s.rule.key === 'length')?.rule;
+ const target = length?.on ? Number(length.current) : NaN;
+ if (!Number.isFinite(target) || target <= 0) return null;
+ const need =
+ Math.min(asked('fanoutH2'), fanouts) * LEAST_SECTION +
+ Math.max(asked('faq'), asked('buyingFaq'), fanouts ? asked('fanoutFaq') : 0) * LEAST_QUESTION +
+ (asked('summary') ? LEAST_SUMMARY : 0);
+ // The page holds them all already: it shows they fit.
+ if (counted.every((status) => status.state === 'ok')) return null;
+ const { max } = lengthBand(target);
+ return need > max ? { need, max } : null;
+}
+
/** How many of the rules in effect are met: off rules and ones the page can't say don't count. */
export function rulesMet(statuses: { rule: ActiveRule; status: RuleStatus }[]): {
met: number;
diff --git a/web/src/lib/content/suggestions.ts b/web/src/lib/content/suggestions.ts
index ae3d788f9..b6f8d86ad 100644
--- a/web/src/lib/content/suggestions.ts
+++ b/web/src/lib/content/suggestions.ts
@@ -85,6 +85,13 @@ export function suggestionLinks(raw: unknown, afterText: string): SuggestionLink
/** The most suggestions decided at once (00217). */
export const MAX_DECIDE = 200;
+/**
+ * The most changes one agent run leaves, as the API caps them
+ * (content-agent.js MAX_AGENT_SUGGESTIONS): a batch this size may have
+ * stopped short, so the editor says to run it again for the rest.
+ */
+export const AGENT_RUN_MAX = 8;
+
/** How many are still open, accepted and rejected. */
export function suggestionCounts(suggestions: DraftSuggestion[]) {
const counts = { open: 0, accepted: 0, rejected: 0 };