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): tell the Content Agent how long an existing page is now, beside its Length (#1627)

Cihanb5658da07ca2
diff --git a/server/src/lib/content-writer.js b/server/src/lib/content-writer.js
index 256dc847d..4e08051d6 100644
--- a/server/src/lib/content-writer.js
+++ b/server/src/lib/content-writer.js
@@ -324,9 +324,27 @@ Call to action: ${opportunityBrief.callToAction || '—'}`;
return 'No brief: plan the sections from the questions and AI searches below.';
}
+/**
+ * An existing page's length now against its Length, and what its
+ * suggestions should do about it: a page told only the Length doesn't know
+ * it's already twice as long (editor test 2026-10-26).
+ */
+export function lengthNow(now, target) {
+ const top = Math.round(target * (1 + LENGTH_TOLERANCE));
+ const bottom = Math.round(target * (1 - LENGTH_TOLERANCE));
+ if (now > top) {
+ return `The page is about ${now} characters now, over its Length: suggest cuts (repetition, filler, the least useful detail) before anything new, and keep each addition short.`;
+ }
+ if (now < bottom) {
+ return `The page is about ${now} characters now, under its Length: add what the questions and rules ask for.`;
+ }
+ return `The page is about ${now} characters now: keep it about this long.`;
+}
+
/**
* What the model is told, for a new page, an existing one (passage by
- * passage) or one it rewrites whole (`current`: keepBlocks' page).
+ * passage, with its length now: lengthNow) or one it rewrites whole
+ * (`current`: keepBlocks' page).
*/
export function buildWritePrompt({
brand,
@@ -341,6 +359,13 @@ export function buildWritePrompt({
current = null,
}) {
const { sources } = input;
+ // An existing page's length now, when its Length is among the rules (as
+ // overLengthLine): Length off keeps the page's length. A rewrite's page
+ // says it in its own lines.
+ const now =
+ passages && !current && input.rules.some((r) => r.key === 'length')
+ ? textLength(draft.body_html ?? '')
+ : null;
// The data, numbered (S1, S2…) as the agent cites it (CE-033).
const of = (kind) => numbered.filter((s) => s.kind === kind);
const rules = input.rules.map((r) => `${r.key}: ${r.name}${r.detail ? ` — ${r.detail}` : ''}`);
@@ -366,7 +391,7 @@ Industry: ${brand?.industry || 'Not specified'}
${siteTypeLine(brand)}Description: ${brand?.description || 'N/A'}
Page type: ${pageTypeFormat(draft.page_type)}
-Length: about ${sources.length} characters.
+Length: about ${sources.length} characters.${now === null ? '' : ` ${lengthNow(now, sources.length)}`}
Brief:
${brief}
diff --git a/server/src/lib/content-writer.test.js b/server/src/lib/content-writer.test.js
index 69edb0dcf..d3b618309 100644
--- a/server/src/lib/content-writer.test.js
+++ b/server/src/lib/content-writer.test.js
@@ -98,6 +98,7 @@ const {
buildWritePrompt,
headingCase,
briefText,
+ lengthNow,
renderPage,
rewriteSystemPrompt,
runDraftWriting,
@@ -1232,6 +1233,42 @@ describe('the write prompt', () => {
);
expect(write('')).toContain('Industry: Coffee\nDescription:');
});
+
+ it('tells an existing page’s suggestions how long it is now, beside its Length', () => {
+ const LENGTH = [{ key: 'length', name: 'Length' }];
+ const prompt = (bodyHtml, passages = [{ tag: 'p', text: 'Brew it slowly.' }], rules = LENGTH) =>
+ buildWritePrompt({
+ brand,
+ draft: draftRow({ body_html: bodyHtml }),
+ brief: 'No brief.',
+ input: { sources: { length: 3000 }, rules, textRules: [] },
+ passages,
+ lockedKeys: new Set(),
+ });
+ // 5,353 characters for a Length of 3,000, as the page that went to Webflow.
+ expect(prompt(`<p>${'x'.repeat(5353)}</p>`)).toContain(
+ 'Length: about 3000 characters. The page is about 5353 characters now, over its Length: suggest cuts',
+ );
+ expect(prompt(`<p>${'x'.repeat(3100)}</p>`)).toContain(
+ 'The page is about 3100 characters now: keep it about this long.',
+ );
+ // A new page has no length yet.
+ expect(prompt('', null)).toContain('Length: about 3000 characters.\n');
+ // Length off keeps the page's length: no cuts asked for it.
+ const off = prompt(`<p>${'x'.repeat(5353)}</p>`, undefined, []);
+ expect(off).toContain('Length: about 3000 characters.\n');
+ expect(off).not.toContain('suggest cuts');
+ expect(off).not.toContain('characters now');
+ });
+});
+
+describe('lengthNow', () => {
+ it('reads a page over, under or within its Length’s band (±20%)', () => {
+ expect(lengthNow(3601, 3000)).toMatch(/over its Length: suggest cuts/);
+ expect(lengthNow(3600, 3000)).toMatch(/keep it about this long/);
+ expect(lengthNow(2400, 3000)).toMatch(/keep it about this long/);
+ expect(lengthNow(2399, 3000)).toMatch(/under its Length: add what/);
+ });
});
describe('the brief rules (2026) in the Content Agent', () => {