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
fix(content): drop an out-of-range Length hint instead of refusing the run, and test the editor's Fix and hand-off calls (#1552 review) (#1553)
Cihana23c0c43006f
diff --git a/server/src/lib/content-agent.js b/server/src/lib/content-agent.jsindex c8be00fd1..fbd62ff85 100644--- a/server/src/lib/content-agent.js+++ b/server/src/lib/content-agent.js@@ -129,13 +129,16 @@ export const fixRulesInput = z.object({* The page past its Length when Length isn't among the rules (held for the* person, or not picked: editor test 2026-10-26): its characters and the* most it may have, so what the agent adds for the other rules stays short.+ * A hint, never a reason to refuse the run: a value out of range (a Length+ * of 0 reads every page as long, at most 0) is dropped.*/overLength: z.object({count: z.number().int().min(0).max(10_000_000),max: z.number().int().min(1).max(10_000_000),})- .optional(),+ .optional()+ .catch(undefined),});export const suggestionsSchema = z.object({@@ -987,7 +990,8 @@ export function buildFixPrompt({if (more) lines.push('(The page goes on; suggest changes only to the passages above.)');const rules = input.rules.map((r) => `- ${r.key}: ${r.name}${r.detail ? ` — ${r.detail}` : ''}`);const own = input.textRules.map((text) => `- ${text}`);- const over = overLengthLine(input.overLength);+ // Said only when the Length isn't among the rules: the line says it isn't.+ const over = input.rules.some((r) => r.key === 'length') ? '' : overLengthLine(input.overLength);return `Brand: ${brand?.name || 'Unknown'}Industry: ${brand?.industry || 'Not specified'}${siteTypeLine(brand)}Description: ${brand?.description || 'N/A'}diff --git a/server/src/lib/content-agent.test.js b/server/src/lib/content-agent.test.jsindex 7efb206a7..9267e8573 100644--- a/server/src/lib/content-agent.test.js+++ b/server/src/lib/content-agent.test.js@@ -230,12 +230,27 @@ describe('the page as the agent reads it', () => {).toMatchObject({overLength: { count: 17_683, max: 16_798 },});- expect(() =>- fixRulesInput.parse({ ...input(), overLength: { count: -1, max: 16_798 } }),- ).toThrow();- expect(() =>- fixRulesInput.parse({ ...input(), overLength: { count: 17_683, max: 0 } }),- ).toThrow();+ // A value out of range is dropped, never a reason to refuse the run.+ for (const overLength of [{ count: -1, max: 16_798 }, { count: 17_683, max: 0 }, 'long']) {+ const parsed = fixRulesInput.parse({ ...input(), overLength });+ expect(parsed.overLength).toBeUndefined();+ expect(parsed.rules).toHaveLength(2);+ }+ // With the Length among the rules, the line isn't said: it says it isn't.+ expect(+ buildFixPrompt({+ brand: { name: 'Acme Coffee', language: 'en' },+ draft: rows.content_drafts,+ passages: draftPassages(BODY),+ lockedKeys: new Set(),+ input: {+ ...input({+ rules: [{ key: 'length', name: 'Length', detail: 'aim 13,998 · 17,683' }],+ }),+ overLength: { count: 17_683, max: 16_798 },+ },+ }),+ ).not.toContain('its Length allows');});it('sends a long page only up to its cap, and no passage too long to change', () => {diff --git a/server/src/lib/content-handoff.test.js b/server/src/lib/content-handoff.test.jsindex a06878517..1f32e80e7 100644--- a/server/src/lib/content-handoff.test.js+++ b/server/src/lib/content-handoff.test.js@@ -91,5 +91,13 @@ describe('handOffDraft', () => {count: 17_683,max: 16_798,});+ // A Length of 0 (at most 0): dropped, and the hand-off runs as before.+ const zero = handOffInput.parse({+ items: [{ key: 'readability:longSentences', detail: '' }],+ overLength: { count: 1_500, max: 0 },+ });+ expect(zero.overLength).toBeUndefined();+ await handOffDraft({ draftId: 'd1', brandId: 'b1', input: zero });+ expect(fixDraftRules.mock.calls.at(-1)[0].input).not.toHaveProperty('overLength');});});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 f7127f8c4..6335adc93 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@@ -2034,6 +2034,8 @@ describe('the content editor', () => {const keys = fixDraftRules.mock.calls[0][2].rules.map((r: { key: string }) => r.key);expect(keys).toContain('aiTraces');expect(keys).not.toContain('sentence');+ // Within its Length (none set here): no overLength.+ expect(fixDraftRules.mock.calls[0][2]).not.toHaveProperty('overLength');} finally {window.innerWidth = width;}@@ -4351,6 +4353,57 @@ describe('the side panel', () => {await act(async () => void (await vi.advanceTimersByTimeAsync(0)));});+ it('tells a hand-off how far past its Length the page is, and only then (#1552 review)', async () => {+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });+ getContentAuthors.mockResolvedValue({+ authors: [],+ brands: [{ id: 'b1', name: 'Ledgerly' }],+ me: { id: 'u1', role: 'admin' },+ });+ const long = `Teams ${Array.from({ length: 39 }, () => 'plan').join(' ')}.`;+ const handOff = async (length: string) => {+ getContentDraft.mockResolvedValue({+ ...claimed,+ bodyHtml: `${claimed.bodyHtml}<p>${long}</p>`,+ rules: {+ set: null,+ source: null,+ overrides: { length: { value: length } },+ textRules: [],+ },+ });+ 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 card = panel()!.querySelector('[aria-label="Hand it off to Content Agent"]')!;+ await act(async () =>+ [...card.querySelectorAll<HTMLButtonElement>('button')]+ .find((b) => b.textContent === 'Hand off')!+ .click(),+ );+ await act(async () => void (await vi.advanceTimersByTimeAsync(0)));+ return handOffDraft.mock.calls.at(-1)![2];+ };+ const again = async (length: string) => {+ await act(async () => root.unmount());+ root = createRoot(container);+ handOffDraft.mockClear();+ return handOff(length);+ };+ // A Length of 100: the page is past its band's top, 120.+ const first = await handOff('100');+ expect(first).toMatchObject({ overLength: { count: expect.any(Number), max: 120 } });+ // Its Length the page's own count: within its band, nothing said.+ expect(await again(String(first.overLength.count))).not.toHaveProperty('overLength');+ // A Length of 0 reads every page as long, at most 0: nothing said either.+ expect(await again('0')).not.toHaveProperty('overLength');+ });+it('hands an imported page off on its own once Quality is read, once a draft, when its brand does (CE-051)', async () => {process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });@@ -6633,6 +6686,25 @@ describe('the side panel', () => {).toContain('would break Max sentence length');});+ it('tells a Fix run how far past its Length the page is when it doesn’t send the Length (#1552 review)', async () => {+ getContentDraft.mockResolvedValue({+ ...traced,+ rules: { set: null, source: null, overrides: { length: { value: '20' } }, textRules: [] },+ });+ getDraftSuggestions.mockResolvedValue([]);+ fixDraftRules.mockResolvedValue({ count: 0 });+ await openRules();+ await act(async () => panelButton('Run Agent').click());+ await act(async () => {});+ const sent = fixDraftRules.mock.calls[0][2];+ // Sent as a rule, it says how far off the page is itself; held, the hint does.+ if (sent.rules.some((r: { key: string }) => r.key === 'length')) {+ expect(sent).not.toHaveProperty('overLength');+ } else {+ expect(sent.overLength).toEqual({ count: expect.any(Number), max: 24 });+ }+ });+it('says the month’s AI usage is used up before anything else, and runs nothing', async () => {aiUsage.usage = usageAt(100);getContentDraft.mockResolvedValue(traced);diff --git a/web/src/lib/content/rules.test.ts b/web/src/lib/content/rules.test.tsindex 575786b2b..b139cf666 100644--- a/web/src/lib/content/rules.test.ts+++ b/web/src/lib/content/rules.test.ts@@ -277,6 +277,11 @@ describe('length and structure', () => {expect(overLengthFor(over, [])).toEqual({ count: 1_500, max: 1_200 });expect(overLengthFor(statuses(1_150), forAgent)).toBeUndefined();expect(overLengthFor(statuses(200), forAgent)).toBeUndefined();+ // A Length of 0 reads every page as long, at most 0: nothing said.+ const zero = activeRules(ruleSet('blog_post'), { overrides: { length: { value: '0' } } }).map(+ (r) => ({ rule: r, status: checkRule(r, page('<h1>T</h1><p>x</p>', 1_500), ctx) }),+ );+ expect(overLengthFor(zero, [])).toBeUndefined();// Length off.const off = activeRules(ruleSet('blog_post'), { overrides: { length: { on: false } } }).map((r) => ({ rule: r, status: checkRule(r, page('<h1>T</h1><p>x</p>', 1_500), ctx) }),diff --git a/web/src/lib/content/rules.ts b/web/src/lib/content/rules.tsindex 057652330..ed579ac02 100644--- a/web/src/lib/content/rules.ts+++ b/web/src/lib/content/rules.ts@@ -820,7 +820,7 @@ export const NO_HELD: ReadonlySet<string> = new Set();* for the person, or not picked; a hand-off sends none: editor test* 2026-10-26): its characters and the most it may have, so what the agent* adds for the other rules stays short. Undefined with Length off, within- * it, or sent.+ * it, sent, or a Length of 0.*/export function overLengthFor<T extends { rule: ActiveRule; status: RuleStatus }>(rules: T[],@@ -829,7 +829,8 @@ export function overLengthFor<T extends { rule: ActiveRule; status: RuleStatus }const length = rules.find(({ rule }) => rule.key === 'length' && rule.on);if (!length || sent.some(({ rule }) => rule.key === 'length')) return undefined;const { status } = length;- return status.state === 'bad' && 'code' in status && status.code === 'long'+ // A Length of 0 reads every page as long, at most 0: nothing to say.+ return status.state === 'bad' && 'code' in status && status.code === 'long' && status.max >= 1? { count: status.count, max: status.max }: undefined;}