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): read a rewrite's attributions line by line, read more wordings and two-name lists, and let a banned word drop only itself (#1520 follow-ups) (#1537)

Cihan64f6d9c430d5
diff --git a/server/src/lib/content-agent.js b/server/src/lib/content-agent.js
index 82e7025af..19a761ff5 100644
--- a/server/src/lib/content-agent.js
+++ b/server/src/lib/content-agent.js
@@ -10,7 +10,9 @@ import { linkAllowList, linkKey, linkTargetsPrompt, readLinkTargets } from './co
import { siteTypeLine, pageTypeFormat } from './content-page-types.js';
import {
NOT_NAMES,
+ SPEECH,
authorWords,
+ editLines,
guardPeopleInHtml,
isKnown,
isRole,
@@ -41,6 +43,7 @@ import {
textPieces,
todayText,
} from './content-sources.js';
+import { draftLanguage } from './content-language.js';
import { getLanguageName } from './languages.js';
import { PlanLimitError, reserveAiBudget } from './plan-guard.js';
@@ -283,6 +286,20 @@ const textOf = (html) =>
.root()
.text();
+/**
+ * HTML's lines as text, as the guards read them (editLines): each block and
+ * each line break apart, a line's inline tags read with it ("<a>Gartner</a>'s
+ * report" whole).
+ */
+export function htmlLines(html) {
+ const lines = [];
+ editLines(cheerio.load(html || '', null, false), (text) => {
+ lines.push(text);
+ return [];
+ });
+ return lines;
+}
+
const isHeading = (tag) => /^h[1-6]$/.test(tag);
/** A question, then what follows it: "?" before a space, or a full-width "?". */
@@ -315,12 +332,16 @@ export function growsPastLimit(passage, before, words) {
*/
// A capitalised word of a name, starting a word: a dot inside it ("Node.js")
// or after an initial ("U.S."), never the one that ends its sentence
-// ("…according to Gartner. The plan").
-const NAME_DOT = String.raw`\.(?=[\p{L}\p{N}])|(?<=(?:^|[^\p{L}\p{N}]|\.)\p{Lu})\.`;
+// ("…according to Gartner. The plan"). A dot is taken one way only: an
+// initial's is one no letter follows, so a run of initials ("U.S.U.S.…")
+// is read in linear time, never tried both ways at each dot.
+const NAME_DOT = String.raw`\.(?=[\p{L}\p{N}])|(?<=(?:^|[^\p{L}\p{N}]|\.)\p{Lu})\.(?![\p{L}\p{N}])`;
+/** The most words a source's name is read with: a run of capitalised words past it isn't one. */
+const MAX_NAME_WORDS = 8;
const NAME_WORD = String.raw`(?<![\p{L}\p{N}&'’.-])\p{Lu}(?:[\p{L}\p{N}&'’-]|${NAME_DOT})*`;
// A name as an attribution gives it: capitalised words, after an article
// or a year ("the Zapier report", "a 2025 Gartner survey").
-const SOURCE_NAME = String.raw`(?<name>(?!(?:The|This|That|These|Those|Our|Their|Its|Your|My|His|Her|We|They|It|A|An)\b)${NAME_WORD}(?:\s+${NAME_WORD})*)`;
+const SOURCE_NAME = String.raw`(?<name>(?!(?:The|This|That|These|Those|Our|Their|Its|Your|My|His|Her|We|They|It|A|An)\b)${NAME_WORD}(?:\s+${NAME_WORD}){0,${MAX_NAME_WORDS - 1}})`;
const LEAD = String.raw`(?:(?:the|a|an)\s+)?(?:\d{4}\s+)?`;
const ATTRIBUTIONS = [
new RegExp(String.raw`\b[Aa]ccording to\s+${LEAD}${SOURCE_NAME}`, 'gu'),
@@ -332,7 +353,14 @@ const ATTRIBUTIONS = [
// "Claims" and "states" are nouns too ("Warranty claims are…", "all 50
// US states"): those, as "reports" and the rest, only before "that".
new RegExp(
- String.raw`${SOURCE_NAME}\s+(?:claims|claimed|states|stated|reports|reported|notes|noted|finds|found|estimates|estimated)\s+that\b`,
+ String.raw`${SOURCE_NAME}\s+(?:reports|reported|notes|noted|finds|found|estimates|estimated)\s+that\b`,
+ 'gu',
+ ),
+ // …and never a run of names counted ("all 50 US states that allow…", "most
+ // US states that", "the 48 contiguous US states that"), or one read from
+ // the middle of a name ("New England states that").
+ new RegExp(
+ String.raw`(?<!(?:\b(?:[Aa]ll|[Mm]ost|[Mm]any|[Ss]ome|[Ss]everal|[Bb]oth|[Ee]very|\d{1,3})(?:\s+\p{Ll}+){0,2}|\p{Lu}[\p{L}\p{N}&.'’-]*)\s+)${SOURCE_NAME}\s+(?:claims|claimed|states|stated)\s+that\b`,
'gu',
),
new RegExp(
@@ -340,9 +368,36 @@ const ATTRIBUTIONS = [
'gu',
),
new RegExp(String.raw`\b[Ll]aut\s+${LEAD}${SOURCE_NAME}`, 'gu'),
- // "Gartner'a göre", never a comparison ("ChatGPT'ye göre daha hızlı").
+ // "As Zapier notes, …", "As Zapier puts it, …": the verb then a comma or
+ // "that", never an event ("As Google adds AI Overviews to more queries").
+ new RegExp(String.raw`\b[Aa]s\s+${LEAD}${SOURCE_NAME}\s+${SPEECH}(?=\s*[,:]|\s+that\b)`, 'gu'),
+ // "a 2025 report by Gartner, …", "a survey from Statista finds": as a
+ // claim's source, never a thing to get ("Download the report from Gartner.").
+ new RegExp(
+ String.raw`\b(?:[Rr]eport|[Ss]tudy|[Ss]urvey|[Pp]aper|[Pp]oll)\s+(?:by|from)\s+${LEAD}${SOURCE_NAME}(?=\s*,|\s+(?:shows?|showed|finds|found|says|said|suggests?|suggested|reveals?|revealed|estimates?|estimated)\b)`,
+ 'gu',
+ ),
+ // "data from Statista shows that …" or a figure, never a tool's ("Data
+ // from GA4 shows where visitors come from").
new RegExp(
- String.raw`(?<name>(?<![\p{L}\p{N}.-])\p{Lu}(?:[\p{L}\p{N}-]|${NAME_DOT})*)['’]\p{L}{1,3}\s+göre\b(?!\s+(?:daha|en)\b)`,
+ String.raw`\b(?:[Dd]ata|[Ff]igures|[Nn]umbers|[Ss]tatistics)\s+from\s+${LEAD}${SOURCE_NAME}\s+(?:shows?|showed|finds|found|suggests?|suggested|reveals?|revealed)(?=\s+(?:that\b|\p{N}))`,
+ 'gu',
+ ),
+ // "laut einer (aktuellen) Studie von Gartner": by "von" only, as German
+ // writes every noun with a capital ("laut der Anleitung des Herstellers").
+ new RegExp(
+ String.raw`\b[Ll]aut\s+(?:einer|einem|der|dem|des)\s+(?:\p{L}+\s+){1,2}von\s+${LEAD}${SOURCE_NAME}`,
+ 'gu',
+ ),
+ // "Gartner'ın raporuna göre": a source's report, study, data or survey.
+ new RegExp(
+ String.raw`(?<name>(?<![\p{L}\p{N}.-])\p{Lu}(?:[\p{L}\p{N}-]|${NAME_DOT})*)['’]\p{L}{1,3}\s+(?:raporuna|araştırmasına|verilerine|anketine|çalışmasına|açıklamasına)\s+göre\b`,
+ 'gu',
+ ),
+ // "Gartner'a göre", never a comparison ("ChatGPT'ye göre daha hızlı");
+ // "en" after it is the source's claim ("Gartner'a göre en hızlı büyüyen").
+ new RegExp(
+ String.raw`(?<name>(?<![\p{L}\p{N}.-])\p{Lu}(?:[\p{L}\p{N}-]|${NAME_DOT})*)['’]\p{L}{1,3}\s+göre\b(?!\s+daha\b)`,
'gu',
),
];
@@ -371,7 +426,12 @@ const attributionsFor = (language) =>
export function attributableSources(pageHtml, numbered, authors = [], language = null) {
const inputs = numbered.filter((s) => s.kind === 'input').map(sourceWords);
return {
- ...knownPeople(...attributedNames(htmlText(pageHtml), language), ...inputs, ...authors),
+ // Read line by line, as a change's blocks are (htmlLines).
+ ...knownPeople(
+ ...htmlLines(pageHtml).flatMap((line) => attributedNames(line, language)),
+ ...inputs,
+ ...authors,
+ ),
language,
};
}
@@ -396,12 +456,18 @@ export function attributedNames(text, language = null) {
/**
* Where a name's own words start: past the words a sentence starts with, a
* role or an adverb ("As Zapier", "CEO Jane Doe", "Recently Gartner"), as
- * personIn (content-people.js) reads a person's.
+ * personIn (content-people.js) reads a person's. Its last word is the name
+ * when it is an "-ly" word or a capitalised role ("Grammarly", "Coach"),
+ * never a sentence's word ("Who says", "Most said") or "CEO" alone.
*/
function nameStart(name) {
- for (const word of name.matchAll(/\S+/g)) {
+ const words = [...name.matchAll(/\S+/g)];
+ for (const [i, word] of words.entries()) {
const lower = word[0].toLowerCase();
- if (!NOT_NAMES.has(lower) && !isRole(lower) && !/^\p{L}+ly$/u.test(lower)) return word.index;
+ if (NOT_NAMES.has(lower)) continue;
+ const ly = /^\p{L}+ly$/u.test(lower);
+ if (!ly && !isRole(lower)) return word.index;
+ if (i === words.length - 1 && (ly || /^\p{Lu}\p{Ll}+$/u.test(word[0]))) return word.index;
}
return name.length;
}
@@ -445,31 +511,92 @@ export function addsAttribution(before, words, known = null) {
* where dropping it would drop the page.
*/
export function placeholderAttributions(text, known = null) {
- const unknown = attributionsIn(text, known?.language)
- .filter((a) => !known || !knownName(a.name, known))
- .sort((a, b) => b.index - a.index);
- let out = String(text);
- for (const { name, index } of unknown) {
- if (out.slice(index, index + name.length) !== name) continue;
- // The name's own words go; a sentence's first word before it stays ("As [source] says").
- const start = nameStart(name);
- if (start >= name.length) continue;
- out = `${out.slice(0, index + start)}[source]${out.slice(index + name.length)}`;
+ const s = String(text);
+ let out = '';
+ let at = 0;
+ for (const e of attributionEdits(s, known)) {
+ out += s.slice(at, e.start) + e.text;
+ at = e.end;
+ }
+ return out + s.slice(at);
+}
+
+/**
+ * Each claim a text gives to a source the agent wasn't given, as an edit
+ * that puts the name's own words as "[source]" (a sentence's first word
+ * before it stays: "As [source] says"), apart and in order: a name two
+ * wordings read ("As Zapier says") goes once.
+ */
+function attributionEdits(text, known) {
+ const edits = [];
+ for (const { name, index } of attributionsIn(text, known?.language)) {
+ if (known && knownName(name, known)) continue;
+ const start = index + nameStart(name);
+ const end = index + name.length;
+ if (start >= end || edits.some((e) => start < e.end && end > e.start)) continue;
+ edits.push({ start, end, text: '[source]' });
}
- return out;
+ return edits.sort((a, b) => a.start - b.start);
+}
+
+/**
+ * An HTML page with each claim given to a source the agent wasn't given put
+ * as a placeholder, line by line in its words (editLines): a name linked to
+ * its page ("According to <a>Zapier</a>, …") is read, and an entity is read
+ * as its character ("AT&T"). The HTML as it was when there's none.
+ */
+export function placeholderAttributionsInHtml(html, known = null) {
+ const $ = cheerio.load(html || '', null, false);
+ if (!editLines($, (text) => attributionEdits(text, known))) return html;
+ // A link whose words all became the placeholder would still give the claim to its page.
+ $('a').each((_, el) => {
+ if ($(el).text() === '[source]') $(el).replaceWith('[source]');
+ });
+ return $.html();
}
// A list of names: two or more capitalised items with commas and an "and"
// ("Ansvisor, Profound and LLM Pulse"; und, ve, et, y…), or three with
// commas; a dot only inside a word, as in a source's name.
const ITEM_WORD = String.raw`(?<![\p{L}\p{N}&+'’.-])\p{Lu}(?:[\p{L}\p{N}&+'’-]|${NAME_DOT})*`;
-const ITEM = String.raw`${ITEM_WORD}(?:\s+${ITEM_WORD})*`;
-const AND = String.raw`(?:and|or|und|oder|ve|veya|ile|et|ou|y|o|e|en|of)`;
+const ITEM = String.raw`${ITEM_WORD}(?:\s+${ITEM_WORD}){0,${MAX_NAME_WORDS - 1}}`;
+const AND = String.raw`(?:and|or|&|und|oder|ve|veya|ile|et|ou|y|o|e|en|of)`;
const NAME_LIST = new RegExp(
String.raw`(?:${ITEM}\s*,\s*)+${ITEM},?\s+${AND}\s+${ITEM}|(?:${ITEM}\s*,\s*){2,}${ITEM}`,
'gu',
);
const ITEM_RE = new RegExp(ITEM, 'gu');
+// Two names ("ChatGPT and Claude", "Shopify & WooCommerce"), read as a list
+// only when one is shaped as a product's or a brand's (a capital after a small
+// letter): "Sales and Marketing", "SEO and AEO", "B2B and B2C" are terms.
+const TWO_NAMES = new RegExp(
+ String.raw`${ITEM}\s+(?:and|or|&|und|oder|ve|veya|ile|et|ou)\s+${ITEM}`,
+ 'gu',
+);
+const BRANDISH = /\p{Ll}\p{Lu}/u;
+
+/** The lists of names a text has: three or more, and two shaped as a brand's. */
+function nameLists(text) {
+ const twos = (text.match(TWO_NAMES) ?? []).filter((pair) =>
+ (pair.match(ITEM_RE) ?? []).some((item) => BRANDISH.test(item)),
+ );
+ return [...(text.match(NAME_LIST) ?? []), ...twos];
+}
+
+/**
+ * The words the Banned words rule lists, as the editor's detail sends them:
+ * "aim: seamless, leverage" then " · now: 3 found" (web/src/lib/content/
+ * agent-write.ts, useRuleDescriber; en.json rules.agent.aim). Empty without
+ * the rule, or without its aim (an empty list): never the count.
+ */
+export function bannedWordsOf(rules = []) {
+ const detail = rules.find((r) => r.key === 'bannedWords')?.detail ?? '';
+ const aim = detail.split(' · ')[0].match(/^aim:\s*(.*)$/i);
+ return (aim?.[1] ?? '')
+ .split(/[,;]/)
+ .map((w) => w.trim())
+ .filter(Boolean);
+}
/**
* Whether a replace drops a name from a list the passage has: a product, a
@@ -479,20 +606,34 @@ const ITEM_RE = new RegExp(ITEM, 'gu');
* month. Each item the replace touches is read in the passage as changed,
* the blocks it adds too, by its last word, whole and in any case, without
* a possessive or a case ending ("Ask ChatGPT" → "ask ChatGPT", "Claude's"
- * → "Claude", "Claude'u" → "Claude'da"). A change made to take out a banned
- * word or an AI trace may.
+ * → "Claude", "Claude'u" → "Claude'da"). Two names count as a list when one
+ * is shaped as a brand's (nameLists). A change made to take out an AI trace
+ * may drop any; one taking out a banned word only the item that is one
+ * (`banned`, bannedWordsOf).
*/
-export function dropsName(passageText, before, words, rules = [], blocksText = '') {
- if (rules.includes('bannedWords') || rules.includes('aiTraces')) return false;
+export function dropsName(passageText, before, words, rules = [], blocksText = '', banned = []) {
+ if (rules.includes('aiTraces')) return false;
+ // Taking out a banned word: the item that is one may go, no other. Without
+ // the rule's words, any may, as before.
+ if (rules.includes('bannedWords') && banned.length === 0) return false;
+ // An item's words without the banned ones: "Leverage Shopify" is still Shopify.
+ const unbanned = (item) =>
+ item
+ .split(/\s+/)
+ .filter(
+ (word) =>
+ !rules.includes('bannedWords') ||
+ !banned.some((b) => isKnown(word.replace(/['’]\p{L}*$/u, ''), knownPeople(b))),
+ );
const text = String(passageText);
const changed = knownPeople(`${text.replace(before, () => words)} ${blocksText}`);
- for (const list of text.match(NAME_LIST) ?? []) {
+ for (const list of nameLists(text)) {
for (const item of list.match(ITEM_RE) ?? []) {
if (!String(before).includes(item)) continue;
- const last = item
- .split(/\s+/)
- .pop()
- .replace(/['’]\p{L}*$/u, '');
+ const rest = unbanned(item);
+ // The item is a banned word: it may go.
+ if (!rest.length) continue;
+ const last = rest.at(-1).replace(/['’]\p{L}*$/u, '');
if (!isKnown(last, changed)) return true;
}
}
@@ -595,6 +736,8 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
// and what it was given (Your input, the authors), never just any name the
// page has (a competitor in a list).
const attributable = sourcing.attributable ?? people;
+ // The Banned words rule's words: a change taking one out may drop that item only.
+ const banned = sourcing.banned ?? [];
const kept = [];
const seen = new Set();
for (const answer of raw) {
@@ -610,11 +753,15 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
const reason = stripSourceIds(s.reason).trim().slice(0, 300);
if (!passage || !reason || passage.text.length > MAX_PASSAGE_CHARS) continue;
const rules = [...new Set(s.rules.filter((key) => ruleKeys.has(key)))];
- const insertOf = (html) =>
- textOf(html).trim() &&
- html.length <= 20_000 &&
- // A claim given to a source it wasn't given (editor test 2026-10-25).
- !addsAttribution('', textOf(html), attributable)
+ // Blocks read line by line (htmlLines): compact HTML
+ // ("<li>ChatGPT</li><li>Gemini</li>") never runs their words together,
+ // and a linked name ("<a>Gartner</a>'s report") is read whole.
+ const insertOf = (html) => {
+ const lines = htmlLines(html);
+ return lines.some((line) => line.trim()) &&
+ html.length <= 20_000 &&
+ // A claim given to a source it wasn't given (editor test 2026-10-25).
+ !lines.some((line) => addsAttribution('', line, attributable))
? {
id: `insert:${passage.text}:${html}`,
row: {
@@ -627,6 +774,7 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
},
}
: null;
+ };
// One suggestion's changes are kept together, or not at all: a split
// replace never leaves a question without its answer.
let changes;
@@ -646,7 +794,12 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
if (
keepsPlaceholders &&
changed &&
- dropsPlaceholder(passage.text, before, `${words} ${textOf(blocks)}`, passage.tag)
+ dropsPlaceholder(
+ passage.text,
+ before,
+ `${words} ${htmlLines(blocks).join(' ')}`,
+ passage.tag,
+ )
) {
continue;
}
@@ -657,7 +810,7 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
asksMoreThanOne(passage, before, words) ||
addsAttribution(before, words, attributable) ||
(!/^h[1-6]$/.test(passage.tag) &&
- dropsName(passage.text, before, words, rules, textOf(blocks))))
+ dropsName(passage.text, before, words, rules, htmlLines(blocks).join(' '), banned)))
)
continue;
changes = [
@@ -894,7 +1047,7 @@ export async function fixDraftRules({ draftId, brandId, input, handoff = null })
const { data: draft, error: draftError } = await supabaseAdmin
.from('content_drafts')
.select(
- `id, brand_id, title, body_html, page_type, action_id, status, source_url, agent_state, agent_state_at${handoff ? ', quality_handoff' : ''}`,
+ `id, brand_id, title, body_html, page_type, rules, action_id, status, source_url, agent_state, agent_state_at${handoff ? ', quality_handoff' : ''}`,
)
.eq('id', draftId)
.maybeSingle();
@@ -1080,7 +1233,12 @@ async function fixWithRun({
);
// The sources a claim may be given to: the ones the page gives claims to,
// and its Your input and authors (never just a name the page lists).
- const attributable = attributableSources(draft.body_html, numbered, authors, brand.language);
+ const attributable = attributableSources(
+ draft.body_html,
+ numbered,
+ authors,
+ await draftLanguage(draft, brand.organization_id, brand.language),
+ );
// Where it may link: the brand's pages and the draft's sources (A); a
// hand-off's source checks link the draft's sources.
const linkKeys =
@@ -1140,7 +1298,14 @@ async function fixWithRun({
lockedKeys,
ruleKeys,
linkAllowList(targets),
- { numbered, known, people, attributable, keepPlaceholders: handoff },
+ {
+ numbered,
+ known,
+ people,
+ attributable,
+ keepPlaceholders: handoff,
+ banned: bannedWordsOf(input.rules),
+ },
);
// Stopped meanwhile: nothing it wrote is kept.
await stopIfStopped(run);
diff --git a/server/src/lib/content-agent.test.js b/server/src/lib/content-agent.test.js
index acae32ce5..dae9e8824 100644
--- a/server/src/lib/content-agent.test.js
+++ b/server/src/lib/content-agent.test.js
@@ -79,11 +79,14 @@ const {
attributedNames,
dropsName,
placeholderAttributions,
+ placeholderAttributionsInHtml,
+ bannedWordsOf,
dropsPlaceholder,
emptyWhy,
fixDraftRules,
keepSuggestions,
growsPastLimit,
+ htmlLines,
HEADING_LIMITS,
inlineText,
MAX_PROMPT_PASSAGE_CHARS,
@@ -431,12 +434,20 @@ describe('keepSuggestions', () => {
});
it('reads no attribution in "per" before a noun, "claims" or "states" as nouns, or a comparison with "göre"', () => {
+ // "states" after a number or "all" is the noun, before "that" too.
+ expect(addsAttribution('', 'We ship to all 50 US states that allow wine delivery.')).toBe(
+ false,
+ );
+ expect(addsAttribution('', 'We ship to all US states that allow it.')).toBe(false);
+ expect(addsAttribution('', 'Gartner states that teams forecast.')).toBe(true);
expect(addsAttribution('', 'Kontaktieren Sie uns per E-Mail.')).toBe(false);
expect(addsAttribution('', 'Pricing is per SKU, or per API call.')).toBe(false);
expect(addsAttribution('', 'It ships to all 50 US states.')).toBe(false);
expect(addsAttribution('', 'Warranty claims are handled in a day.')).toBe(false);
expect(addsAttribution('', "Gemini, ChatGPT'ye göre daha hızlı.")).toBe(false);
- expect(addsAttribution('', "ChatGPT'ye göre en iyisi Gemini.")).toBe(false);
+ // "en" after "göre" is the source's claim: "according to ChatGPT, the best one is Gemini".
+ expect(addsAttribution('', "ChatGPT'ye göre en iyisi Gemini.")).toBe(true);
+ expect(addsAttribution('', "Gartner'a göre en hızlı büyüyen pazar Hindistan.")).toBe(true);
// The attributions themselves still are.
expect(addsAttribution('', 'Per Gartner, teams forecast.')).toBe(true);
expect(addsAttribution('', "Per Gartner's survey, teams forecast.")).toBe(true);
@@ -488,6 +499,106 @@ describe('keepSuggestions', () => {
expect(addsAttribution('', 'Per SKU, you pay once.', english)).toBe(true);
});
+ it('reads a rewrite’s HTML line by line: a linked name, an entity', () => {
+ const known = knownPeople('According to Gartner, teams forecast.');
+ expect(
+ placeholderAttributionsInHtml(
+ '<p>According to <a href="https://zapier.com/blog">Zapier</a>, teams forecast.</p>',
+ known,
+ ),
+ // The link goes too: it would still give the claim to its page.
+ ).toBe('<p>According to [source], teams forecast.</p>');
+ expect(placeholderAttributionsInHtml('<p>According to AT&amp;T, most do.</p>', known)).toBe(
+ '<p>According to [source], most do.</p>',
+ );
+ // A line break ends a line: the next one's first word isn't the name's.
+ expect(
+ placeholderAttributionsInHtml('<p>According to Zapier<br>The plan is monthly.</p>', known),
+ ).toBe('<p>According to [source]<br>The plan is monthly.</p>');
+ // A known one, and a page with none: the HTML as it was.
+ const html = '<h2>Plans</h2><p>According to <strong>Gartner</strong>, teams plan.</p>';
+ expect(placeholderAttributionsInHtml(html, known)).toBe(html);
+ });
+
+ it('reads more wordings: "As X notes", "a report by X", "data from X shows", Turkish and German', () => {
+ for (const text of [
+ 'As Zapier notes, teams forecast.',
+ 'As Zapier puts it, teams forecast.',
+ 'According to a 2025 report by Gartner, teams forecast.',
+ 'A survey from Statista finds teams forecast.',
+ 'Data from Statista shows that teams forecast.',
+ 'Data from Statista shows 60% of teams forecast.',
+ "Gartner'ın raporuna göre ekipler tahmin eder.",
+ 'Laut einer aktuellen Studie von Gartner planen Teams.',
+ ]) {
+ expect(addsAttribution('', text), text).toBe(true);
+ }
+ // What a product does, an event or a thing to get isn't an attribution.
+ for (const text of [
+ 'Data from Shopify syncs every hour.',
+ 'Data from GA4 shows where visitors come from.',
+ 'As Google adds AI Overviews to more queries, clicks fall.',
+ 'Visibility shifts as ChatGPT adds shopping results.',
+ 'Download the 2025 report from Gartner.',
+ 'Keyword research from Ahrefs helps you plan.',
+ 'Laut der Anleitung des Herstellers geht es so.',
+ ]) {
+ expect(addsAttribution('', text), text).toBe(false);
+ }
+ expect(
+ placeholderAttributions('As Zapier notes, teams forecast.', knownPeople('Gartner')),
+ ).toBe('As [source] notes, teams forecast.');
+ });
+
+ it('reads two names as a list when one is shaped as a brand’s, and "&"', () => {
+ expect(drops('Track ChatGPT and Claude.', 'Track ChatGPT.')).toBe(true);
+ expect(drops('Sync Shopify & WooCommerce stores.', 'Sync Shopify stores.')).toBe(true);
+ expect(drops('Ansvisor, Profound & Peec AI track it.', 'Ansvisor and Profound track it.')).toBe(
+ true,
+ );
+ // Two nouns, two terms: not a list.
+ expect(drops('For Sales and Marketing teams.', 'For marketing teams.')).toBe(false);
+ expect(drops('Combine SEO and AEO.', 'Combine SEO.')).toBe(false);
+ expect(drops('For B2B and B2C shops.', 'For B2B shops.')).toBe(false);
+ });
+
+ it('lets a change for a banned word drop only the item that is one', () => {
+ const rules = [{ key: 'bannedWords', name: 'Banned words', detail: 'Aim: seamless, Claude' }];
+ expect(bannedWordsOf(rules)).toEqual(['seamless', 'Claude']);
+ expect(bannedWordsOf([])).toEqual([]);
+ // As the editor sends it, with the count after; never the count alone.
+ expect(
+ bannedWordsOf([
+ { key: 'bannedWords', name: 'x', detail: 'aim: seamless, leverage · now: 2 found' },
+ ]),
+ ).toEqual(['seamless', 'leverage']);
+ expect(bannedWordsOf([{ key: 'bannedWords', name: 'x', detail: 'now: 3 found' }])).toEqual([]);
+ const banned = bannedWordsOf(rules);
+ const passage = 'Track ChatGPT, Gemini and Claude.';
+ expect(
+ dropsName(passage, passage, 'Track ChatGPT and Gemini.', ['bannedWords'], '', banned),
+ ).toBe(false);
+ expect(
+ dropsName(passage, passage, 'Track ChatGPT and Claude.', ['bannedWords'], '', banned),
+ ).toBe(true);
+ // The banned word goes; the name in the same item stays.
+ const shops = 'Leverage Shopify, WooCommerce and Magento.';
+ const leverage = ['leverage'];
+ expect(
+ dropsName(shops, shops, 'Use WooCommerce and Magento.', ['bannedWords'], '', leverage),
+ ).toBe(true);
+ expect(
+ dropsName(
+ shops,
+ shops,
+ 'Use Shopify, WooCommerce and Magento.',
+ ['bannedWords'],
+ '',
+ leverage,
+ ),
+ ).toBe(false);
+ });
+
it('reads a long run of capitals quickly', () => {
const started = Date.now();
addsAttribution('', `According to ${'A'.repeat(20000)} says that.`);
@@ -496,6 +607,25 @@ describe('keepSuggestions', () => {
expect(Date.now() - started).toBeLessThan(500);
});
+ it('reads a long run of initials quickly: each dot is read one way', () => {
+ const initials = 'U.S.'.repeat(10_000);
+ const started = Date.now();
+ addsAttribution('', `According to ${initials} says that.`);
+ dropsName(`${initials}, C and D`, `${initials}, C and D`, 'C and D');
+ placeholderAttributions(`Per ${initials}'s survey, most do.`);
+ expect(Date.now() - started).toBeLessThan(500);
+ // Dotted names read as before.
+ expect(attributedNames('Built on Node.js, according to the U.S Census.')).toEqual([
+ 'U.S Census',
+ ]);
+ expect(attributedNames('According to the U.S. Census Bureau, most do.')).toEqual([
+ 'U.S. Census Bureau',
+ ]);
+ expect(attributedNames('According to J.D. Power, most do.')).toEqual(['J.D. Power']);
+ expect(attributedNames('Teams forecast, per the U.N.')).toEqual(['U.N.']);
+ expect(attributedNames("U.S.'e göre enflasyon düştü.")).toEqual(['U.S.']);
+ });
+
it('knows a source by its possessive, and never by its last word alone', () => {
const known = knownPeople('According to Gartner, teams forecast.', 'Our research team');
expect(
@@ -632,6 +762,110 @@ describe('keepSuggestions', () => {
* line ("What is LLM SEO? LLM SEO optimizes…", "Frequently Asked
* QuestionsWhat is an AEO tracker?…"): it now goes after the heading.
*/
+describe('blocks, names and languages as the review read them (#1520)', () => {
+ const listed = [{ tag: 'p', text: 'Track ChatGPT, Gemini and Claude.' }];
+ const keep = (s, over = {}) =>
+ keepSuggestions([s], listed, new Set(), new Set(['dated']), null, { ...sourcing, ...over });
+ const insert = (after) =>
+ suggestion({ kind: 'insert', passage: 1, before: '', after, sources: [], marks: [] });
+
+ it('reads compact blocks with a space between them, as it reads the page', () => {
+ // A list turned into bullets, written compact: every name is still there.
+ const bullets = suggestion({
+ passage: 1,
+ before: 'Track ChatGPT, Gemini and Claude.',
+ after: 'Track these engines:<ul><li>ChatGPT</li><li>Gemini</li><li>Claude</li></ul>',
+ sources: [],
+ marks: [],
+ });
+ expect(keep(bullets).map((row) => row.kind)).toEqual(['replace', 'insert']);
+ // A page that cites Gartner: a block after the one citing it isn't read into its name.
+ const cites = attributableSources('<p>According to Gartner, teams forecast.</p>', [], []);
+ expect(
+ keep(
+ insert('<p>Teams plan weekly, according to Gartner.</p><p>Most teams plan monthly.</p>'),
+ {
+ attributable: cites,
+ },
+ ),
+ ).toHaveLength(1);
+ // A heading before the claim doesn't hide it.
+ expect(
+ keep(insert('<h2>Forecasting basics</h2><p>According to Zapier, teams forecast.</p>'), {
+ attributable: cites,
+ }),
+ ).toEqual([]);
+ });
+
+ it('reads a name of eight words at most, so a long run of capitals reads fast', () => {
+ const run = Array.from(
+ { length: 3000 },
+ (_, i) => `Word${String.fromCharCode(65 + (i % 26))}`,
+ ).join(' ');
+ const started = Date.now();
+ attributedNames(`${run} says teams forecast.`);
+ dropsName(`${run}, Alpha and Beta.`, `${run}, Alpha and Beta.`, `${run} and Alpha.`);
+ expect(Date.now() - started).toBeLessThan(500);
+ expect(attributedNames('Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota says so.')).toEqual([
+ 'Beta Gamma Delta Epsilon Zeta Eta Theta Iota',
+ ]);
+ });
+
+ it('never skips a name’s last word: "Grammarly" is a name', () => {
+ const known = knownPeople('According to Grammarly, teams write faster.');
+ expect(addsAttribution('', 'According to Grammarly, most teams do.', known)).toBe(false);
+ expect(placeholderAttributions('According to Grammarly, most teams do.', knownPeople(''))).toBe(
+ 'According to [source], most teams do.',
+ );
+ });
+
+ it('reads a change line by line: a linked name whole, a heading apart from the line after it', () => {
+ expect(
+ htmlLines('<h2>Forecasting Basics</h2><p>Per <a href="#">Gartner</a>’s survey, most do.</p>'),
+ ).toEqual(['Forecasting Basics', 'Per Gartner’s survey, most do.']);
+ const cites = attributableSources(
+ '<p><a href="https://gartner.example">Gartner</a>’s report shows teams forecast.</p>',
+ [],
+ [],
+ );
+ // The page's linked source is read, and a Title Case heading doesn't run into it.
+ expect(
+ keep(insert('<h2>Forecasting Basics</h2><p>Gartner says most teams forecast.</p>'), {
+ attributable: cites,
+ }),
+ ).toHaveLength(1);
+ });
+
+ it('never reads a name past a sentence’s word or a lone "CEO"', () => {
+ const none = knownPeople('');
+ for (const text of [
+ 'Who says B2B content has to be boring?',
+ 'Most said they use ChatGPT weekly.',
+ 'Our CEO said that we ship weekly.',
+ ]) {
+ expect(placeholderAttributions(text, none), text).toBe(text);
+ }
+ });
+
+ it('reads "states" and "claims" as nouns after a count, and reads years before a source', () => {
+ for (const text of [
+ 'We ship to all 50 US states that allow wine delivery.',
+ 'It works in most US states that allow it.',
+ 'We ship to the 48 contiguous US states that allow it.',
+ 'It covers all 50 New England states that allow it.',
+ ]) {
+ expect(addsAttribution('', text), text).toBe(false);
+ }
+ for (const text of [
+ 'By 2026 Gartner estimates that most teams will forecast weekly.',
+ 'In 2025 Gartner found that most teams forecast weekly.',
+ 'In Q3 2025 IDC estimated that most teams forecast weekly.',
+ ]) {
+ expect(addsAttribution('', text), text).toBe(true);
+ }
+ });
+});
+
describe('no invented people or quotes (CE-044)', () => {
const passages = draftPassages(BODY);
const ruleKeys = new Set(['dated', 'faq']);
@@ -1083,6 +1317,29 @@ describe('cleanInsertHtml', () => {
});
describe('fixDraftRules', () => {
+ it('reads attributions in the page’s language: its Language rule, or My rules’ when it has none', async () => {
+ // ", per E-Mail." gives a claim to a source on an English page, never on a German one.
+ const perEmail = suggestion({
+ after: 'good coffee and hot water; order by phone, per E-Mail',
+ sources: [],
+ marks: [],
+ });
+ const fix = async () => {
+ generateObject.mockResolvedValue({
+ object: { suggestions: [perEmail] },
+ usage: { inputTokens: 900, outputTokens: 200 },
+ });
+ return (await fixDraftRules({ draftId: DRAFT, brandId: BRAND, input: input() })).count;
+ };
+ expect(await fix()).toBe(0);
+ rows.content_drafts.rules = { overrides: { language: { value: 'German' } } };
+ expect(await fix()).toBe(1);
+ // No rules of its own: the workspace's My rules for its page type.
+ rows.content_drafts.rules = null;
+ rows.content_rule_sets = { overrides: { language: { value: 'German' } } };
+ expect(await fix()).toBe(1);
+ });
+
it('charges the budget, asks the model and keeps one batch for review', async () => {
generateObject.mockResolvedValue({
object: {
diff --git a/server/src/lib/content-delivery.js b/server/src/lib/content-delivery.js
index 3c2097c86..c50f8ff78 100644
--- a/server/src/lib/content-delivery.js
+++ b/server/src/lib/content-delivery.js
@@ -4,7 +4,7 @@ import { z } from 'zod';
import supabaseAdmin from '../config/supabase.js';
import { logger } from './logger.js';
import { PageFetchError } from './safe-fetch.js';
-import { languageCodeOf } from './languages.js';
+import { rulesLanguage, untouchedRules } from './content-language.js';
import { postJson } from './safe-post.js';
import { isWebflowConfigured } from './composio.js';
import { sendToWebflow } from './cms/webflow-delivery.js';
@@ -434,14 +434,7 @@ async function deliverBatch(going, { brand, configs, webflow, batchId }) {
}
/** A draft no one has set rules on: the workspace's My rules apply (rules.ts effectiveRules). */
-function untouched(rules) {
- return (
- !rules ||
- (rules.source == null &&
- !Object.keys(rules.overrides ?? {}).length &&
- !(rules.textRules ?? []).length)
- );
-}
+const untouched = untouchedRules;
/** The workspace's My rules (00214) for these drafts' types, by type; none when unread. */
async function myRuleSets(orgId, drafts) {
@@ -564,16 +557,12 @@ export async function sendContentPages({
const rules = untouched(draft.rules)
? mine.get(draft.rules?.set ?? draft.page_type)
: draft.rules;
- const rule = rules?.overrides?.language;
item.page = {
...item.page,
method: draft.method ?? null,
sourceUrl: draft.source_url ?? null,
pageType: draft.page_type ?? null,
- language:
- (rule?.on !== false && languageCodeOf(rule?.value)) ||
- languageCodeOf(brand.language) ||
- 'en',
+ language: rulesLanguage(rules, brand.language) || 'en',
};
}
if (pages.length === 1) {
diff --git a/server/src/lib/content-language.js b/server/src/lib/content-language.js
new file mode 100644
index 000000000..3bc373cda
--- /dev/null
+++ b/server/src/lib/content-language.js
@@ -0,0 +1,49 @@
+import supabaseAdmin from '../config/supabase.js';
+import { logger } from './logger.js';
+import { languageCodeOf } from './languages.js';
+
+/**
+ * A page's language, as the editor shows it and the CMS send reads it: its
+ * Language rule's value while the rule is on — the draft's own rules, or the
+ * workspace's My rules for its page type when no one has set rules on the
+ * draft — else the brand's. The Content Agent reads a page's attributions in
+ * it ("per E-Mail" is no source on a German page of an English brand).
+ */
+
+/** Whether a draft's rules are as the editor started them, so My rules stand in for them. */
+export function untouchedRules(rules) {
+ return (
+ !rules ||
+ (rules.source == null &&
+ !Object.keys(rules.overrides ?? {}).length &&
+ !(rules.textRules ?? []).length)
+ );
+}
+
+/** The language a draft's rules (or a My rules set) name, else the brand's; null for none known. */
+export function rulesLanguage(rules, brandLanguage) {
+ const rule = rules?.overrides?.language;
+ return (
+ (rule?.on !== false && languageCodeOf(rule?.value)) || languageCodeOf(brandLanguage) || null
+ );
+}
+
+/**
+ * A draft's language, reading the workspace's My rules for its page type
+ * when it has no rules of its own. A failed read leaves the brand's.
+ */
+export async function draftLanguage(draft, organizationId, brandLanguage) {
+ let rules = draft.rules;
+ const type = rules?.set ?? draft.page_type;
+ if (untouchedRules(rules) && type && organizationId) {
+ const { data, error } = await supabaseAdmin
+ .from('content_rule_sets')
+ .select('overrides')
+ .eq('organization_id', organizationId)
+ .eq('page_type', type)
+ .maybeSingle();
+ if (error) logger.warn({ err: error }, '[content-language] My rules not read');
+ rules = error ? null : (data ?? null);
+ }
+ return rulesLanguage(rules, brandLanguage);
+}
diff --git a/server/src/lib/content-language.test.js b/server/src/lib/content-language.test.js
new file mode 100644
index 000000000..a2c8674a7
--- /dev/null
+++ b/server/src/lib/content-language.test.js
@@ -0,0 +1,80 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+/** A page's language, as the editor and the CMS send read it. */
+
+let rows;
+let reads;
+vi.mock('../config/supabase.js', () => ({
+ default: {
+ from: (table) => {
+ const call = { table, filters: [] };
+ reads.push(call);
+ const chain = {
+ select: () => chain,
+ eq: (col, v) => (call.filters.push([col, v]), chain),
+ maybeSingle: async () => rows[table] ?? { data: null, error: null },
+ };
+ return chain;
+ },
+ },
+}));
+vi.mock('./logger.js', () => ({ logger: { warn: vi.fn() } }));
+
+const { draftLanguage, rulesLanguage, untouchedRules } = await import('./content-language.js');
+
+beforeEach(() => {
+ rows = {};
+ reads = [];
+});
+
+describe('rulesLanguage', () => {
+ it('reads the Language rule while it is on, else the brand’s', () => {
+ expect(rulesLanguage({ overrides: { language: { value: 'German' } } }, 'en')).toBe('de');
+ expect(rulesLanguage({ overrides: { language: { value: 'English (US)' } } }, 'tr')).toBe('en');
+ expect(rulesLanguage({ overrides: { language: { value: 'German', on: false } } }, 'tr')).toBe(
+ 'tr',
+ );
+ expect(rulesLanguage(null, 'Turkish')).toBe('tr');
+ expect(rulesLanguage(null, null)).toBeNull();
+ });
+});
+
+describe('untouchedRules', () => {
+ it('is a draft no one has set rules on', () => {
+ expect(untouchedRules(null)).toBe(true);
+ expect(untouchedRules({ set: 'guide', overrides: {}, textRules: [] })).toBe(true);
+ expect(untouchedRules({ overrides: { language: { value: 'German' } } })).toBe(false);
+ expect(untouchedRules({ source: 'import' })).toBe(false);
+ });
+});
+
+describe('draftLanguage', () => {
+ it('reads the draft’s own rules, without My rules', async () => {
+ const draft = { page_type: 'guide', rules: { overrides: { language: { value: 'German' } } } };
+ expect(await draftLanguage(draft, 'org-1', 'en')).toBe('de');
+ expect(reads).toEqual([]);
+ });
+
+ it('reads My rules for its page type when it has none of its own', async () => {
+ rows.content_rule_sets = {
+ data: { overrides: { language: { value: 'German' } } },
+ error: null,
+ };
+ expect(await draftLanguage({ page_type: 'guide', rules: null }, 'org-1', 'en')).toBe('de');
+ expect(reads[0]).toEqual({
+ table: 'content_rule_sets',
+ filters: [
+ ['organization_id', 'org-1'],
+ ['page_type', 'guide'],
+ ],
+ });
+ // The set a draft's rules name, over its page type.
+ await draftLanguage({ page_type: 'guide', rules: { set: 'best_of' } }, 'org-1', 'en');
+ expect(reads[1].filters[1]).toEqual(['page_type', 'best_of']);
+ });
+
+ it('keeps the brand’s when My rules can’t be read', async () => {
+ rows.content_rule_sets = { data: null, error: new Error('down') };
+ expect(await draftLanguage({ page_type: 'guide', rules: null }, 'org-1', 'tr')).toBe('tr');
+ });
+});
diff --git a/server/src/lib/content-people.js b/server/src/lib/content-people.js
index e53c68a44..b9a7714bc 100644
--- a/server/src/lib/content-people.js
+++ b/server/src/lib/content-people.js
@@ -241,7 +241,7 @@ export const isRole = (lower) =>
const NOT_TITLE_NEXT = `(?!(?:${[...TITLE_NOUNS].map(eitherCase).join('|')})(?!\\p{L}))`;
/** Speech, read with a quote: whoever or whatever says it, it is a quote. */
-const SPEECH = String.raw`(?:says|said|told|tells|explains|explained|notes|noted|writes|wrote|recalls|recalled|adds|added|argues|argued|believes|warns|warned|states|stated|puts it|put it|emphasi[sz]es|emphasi[sz]ed|suggests|suggested|recommends|recommended|advises|advised|points out|pointed out|shares|shared|observes|observed|insists|insisted|admits|admitted|comments|commented|agrees|agreed|claims|claimed|predicts|predicted|describes|described|sagt|sagte|meint|erklärt|dit|explique|dice|explica|afirma|söyledi|diyor|belirtti|açıkladı|dedi|anlattı)`;
+export const SPEECH = String.raw`(?:says|said|told|tells|explains|explained|notes|noted|writes|wrote|recalls|recalled|adds|added|argues|argued|believes|warns|warned|states|stated|puts it|put it|emphasi[sz]es|emphasi[sz]ed|suggests|suggested|recommends|recommended|advises|advised|points out|pointed out|shares|shared|observes|observed|insists|insisted|admits|admitted|comments|commented|agrees|agreed|claims|claimed|predicts|predicted|describes|described|sagt|sagte|meint|erklärt|dit|explique|dice|explica|afirma|söyledi|diyor|belirtti|açıkladı|dedi|anlattı)`;
/**
* Verbs said of people only, read with a name that has no honorific or role
* ("Marco Rossi said"): the rest of SPEECH a product or a company does too
@@ -612,11 +612,28 @@ export function guardPeopleInHtml(html, known) {
});
});
+ count += editLines($, (text, heading) => peopleEdits(text, known, { heading }));
+ if (!count) return { html, count };
+ return { html: $.html(), count };
+}
+
+/**
+ * Edits a loaded HTML's words line by line: each line's text, its own text
+ * nodes and its inline tags' (bold, links) in order, read as one, so a name
+ * or a phrase across a link is read whole and an entity is read as its
+ * character ("AT&T", never "AT&amp;T"). `editsFor(text, heading)` gives a
+ * line's edits, { start, end, text }, apart and in order; each goes in the
+ * text node it starts in, the rest of its words cut. A link or a bold whose
+ * words all went goes too. Code and what isn't words are left alone.
+ * Returns how many edits were made.
+ */
+export function editLines($, editsFor) {
+ let count = 0;
// A line: its own text nodes and its inline tags', in order, read as one.
const line = (nodes, heading) => {
if (!nodes.length) return;
const joined = nodes.map((n) => n.data).join('');
- const edits = peopleEdits(joined, known, { heading });
+ const edits = editsFor(joined, heading);
if (!edits.length) return;
count += edits.length;
const starts = [];
@@ -654,7 +671,11 @@ export function guardPeopleInHtml(html, known) {
for (const node of $(el).contents().get()) {
if (node.type === 'text') run.push(node);
else if (node.type !== 'tag' || KEPT_AS_IS.has(node.name)) continue;
- else if (BLOCKS.has(node.name)) {
+ // A line break ends a line: "Gartner<br>The plan" is two.
+ else if (node.name === 'br') {
+ line(run, heading);
+ run = [];
+ } else if (BLOCKS.has(node.name)) {
line(run, heading);
run = [];
walk(node, HEADINGS.has(node.name));
@@ -663,12 +684,13 @@ export function guardPeopleInHtml(html, known) {
line(run, heading);
};
walk($.root(), false);
- if (!count) return { html, count };
- // A link or a bold whose words all went with a name or a quote goes too.
- $('a, strong, em, b, i, u, s, span, mark, small, sup, sub').each((_, el) => {
- if (!$(el).text() && !$(el).find('img, br').length) $(el).remove();
- });
- return { html: $.html(), count };
+ if (count) {
+ // A link or a bold whose words all went with an edit goes too.
+ $('a, strong, em, b, i, u, s, span, mark, small, sup, sub').each((_, el) => {
+ if (!$(el).text() && !$(el).find('img, br').length) $(el).remove();
+ });
+ }
+ return count;
}
/**
diff --git a/server/src/lib/content-writer.js b/server/src/lib/content-writer.js
index d40e15882..a7439bff2 100644
--- a/server/src/lib/content-writer.js
+++ b/server/src/lib/content-writer.js
@@ -6,7 +6,8 @@ import { resolveModel } from './ai-provider.js';
import {
ATTRIBUTION_RULE,
attributableSources,
- placeholderAttributions,
+ bannedWordsOf,
+ placeholderAttributionsInHtml,
FANOUT_RULE,
HEADING_RULE,
LINK_RULE,
@@ -22,6 +23,7 @@ import {
} from './content-agent.js';
import { contentBriefModelId, rebuildSources } from './content-brief.js';
import { inputSources, readDraftInputs } from './content-inputs.js';
+import { draftLanguage } from './content-language.js';
import { linkAllowList, linkTargetsPrompt, readLinkTargets } from './content-links.js';
import { siteTypeLine, pageTypeFormat } from './content-page-types.js';
import { authorWords, guardPeople, guardPeopleInHtml, knownPeople } from './content-people.js';
@@ -373,7 +375,7 @@ export async function startDraftWriting({ draftId, brandId, input, rewrite = fal
const { data: draft, error: draftError } = await supabaseAdmin
.from('content_drafts')
.select(
- 'id, brand_id, title, page_type, method, source_url, body_html, status, agent_state, agent_state_at, opportunity_id, brief, action_id',
+ 'id, brand_id, title, page_type, rules, method, source_url, body_html, status, agent_state, agent_state_at, opportunity_id, brief, action_id',
)
.eq('id', draftId)
.maybeSingle();
@@ -594,7 +596,7 @@ async function rewritePage({
// passages are never touched.
const cleaned = cleanPageHtml(
// A claim given to a source it wasn't given: a placeholder, not the page dropped.
- placeholderAttributions(guardPeopleInHtml(answer.html, people).html, attributable),
+ placeholderAttributionsInHtml(guardPeopleInHtml(answer.html, people).html, attributable),
rewriteLinks(draft.body_html, linkAllowList(targets)),
{ h1Kept: page.h1Token !== null, originalH1: page.h1 },
);
@@ -865,7 +867,12 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
);
// The sources a claim may be given to: the ones the page gives claims to,
// its Your input and authors (editor test 2026-10-25).
- const attributable = attributableSources(draft.body_html, numbered, authors, brand.language);
+ const attributable = attributableSources(
+ draft.body_html,
+ numbered,
+ authors,
+ await draftLanguage(draft, brand.organization_id, brand.language),
+ );
if (rewrite) {
return await rewritePage({
@@ -964,7 +971,7 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
lockedKeys,
ruleKeys,
linkAllowList(targets),
- { numbered, known, people, attributable },
+ { numbered, known, people, attributable, banned: bannedWordsOf(input.rules) },
);
// Stopped meanwhile: nothing it wrote is kept.
await stopIfStopped(run);