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): keep no agent change that gives a claim to a source it wasn't given or drops a name from a list (#1520)

Cihan9f8b88021f5f
diff --git a/server/src/lib/content-agent.js b/server/src/lib/content-agent.js
index 873993bbb..82e7025af 100644
--- a/server/src/lib/content-agent.js
+++ b/server/src/lib/content-agent.js
@@ -8,7 +8,14 @@ import { contentBriefModelId, rebuildSources } from './content-brief.js';
import { inputSources, readDraftInputs } from './content-inputs.js';
import { linkAllowList, linkKey, linkTargetsPrompt, readLinkTargets } from './content-links.js';
import { siteTypeLine, pageTypeFormat } from './content-page-types.js';
-import { authorWords, guardPeopleInHtml, knownPeople } from './content-people.js';
+import {
+ NOT_NAMES,
+ authorWords,
+ guardPeopleInHtml,
+ isKnown,
+ isRole,
+ knownPeople,
+} from './content-people.js';
import {
RunStoppedError,
advanceRun,
@@ -81,6 +88,9 @@ export const FANOUT_RULE = `- Fan-outs are the searches AI engines run for the p
/** The links rule both agent prompts give the model: only the URLs listed, never invented. */
export const LINK_RULE = `- Links: link only to a URL listed under the pages or sources you may link to, copied exactly, as <a href="URL">the words it explains</a>, in a replace's "after" or in an insert. Cite a source by linking the words it supports. Never invent a URL, never link a heading, and when no listed page fits, add no link.`;
+/** What the agent may say of a source, and the names a list keeps (editor test 2026-10-25). */
+export const ATTRIBUTION_RULE = `- Never give a claim to a source that neither the page nor Your input gives ("According to X…", "X says…", "X found that…"): you don't see what a cited page or a link says. A link goes on the words it explains, never as a source for a claim. Keep every name a list has (products, brands, people): never drop one.`;
+
/** The shortest answer a heading's replace may carry for it to go under the heading. */
const MIN_ANSWER_CHARS = 40;
@@ -154,6 +164,7 @@ ${FANOUT_RULE}
- Never change a passage marked LOCKED: AI assistants quote its wording today. You may insert after it.
- Use only facts from the page, the brand and your data. Never invent numbers, prices, dates, names, sources or quotes. When a rule needs a fact you don't have, write a placeholder in square brackets, e.g. [figure, source, year].
${SOURCES_RULE}
+${ATTRIBUTION_RULE}
- Keep the page's voice and change as little as each rule needs. At most ${MAX_AGENT_SUGGESTIONS} suggestions.
- "reason" says in a few words what the change does and why, e.g. "add a dated data point (rule)".
- Write in the language asked for.`;
@@ -295,6 +306,199 @@ export function growsPastLimit(passage, before, words) {
return then > headingLimit(passage.tag) && then > now;
}
+/**
+ * Attributions a change can write: "According to Zapier…", "as reported by
+ * Gartner", "per Forrester", "Zapier says…", "Zapier found that…", "laut
+ * Zapier", "Zapier'e göre". The agent never sees what a cited page or a link
+ * says (SOURCES_RULE), so one it adds puts a claim in a source's mouth
+ * (editor test 2026-10-25: an AI Overview's claim given to Zapier).
+ */
+// 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})\.`;
+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 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'),
+ new RegExp(
+ String.raw`\b[Aa]s\s+(?:reported|noted|stated|found)\s+by\s+${LEAD}${SOURCE_NAME}`,
+ 'gu',
+ ),
+ new RegExp(String.raw`${SOURCE_NAME}\s+(?:says|said)\b`, 'gu'),
+ // "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`,
+ 'gu',
+ ),
+ new RegExp(
+ String.raw`${SOURCE_NAME}(?:['’]s)?\s+(?:report|study|survey|research|data|analysis)\s+(?:shows|showed|finds|found|says|said|suggests)\b`,
+ '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ı").
+ 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)`,
+ 'gu',
+ ),
+];
+
+/**
+ * "Per Gartner, …", "per Gartner's survey", "…, per Gartner.": read on an
+ * English page only, as German writes "per E-Mail", "per App" (an English
+ * "Per SKU, you pay…" still reads as one: an acronym may be a source too,
+ * "Per IDC, …").
+ */
+const PER_ATTRIBUTIONS = [
+ new RegExp(String.raw`\bPer\s+${LEAD}${SOURCE_NAME}(?=\s*,)`, 'gu'),
+ new RegExp(String.raw`\b[Pp]er\s+${LEAD}${SOURCE_NAME}(?=['’]s\b)`, 'gu'),
+ new RegExp(String.raw`,\s*per\s+${LEAD}${SOURCE_NAME}(?=\s*[.;!?]|\s*$)`, 'gu'),
+];
+
+/** The attributions read on a page in this language: "per" on an English one (or one not said). */
+const attributionsFor = (language) =>
+ !language || /^en\b/i.test(language) ? [...ATTRIBUTIONS, ...PER_ATTRIBUTIONS] : ATTRIBUTIONS;
+
+/**
+ * The sources a claim may be given to on a page: the names it gives claims
+ * to already, Brief › Your input's (an expert, the person's own data) and
+ * the workspace's authors.
+ */
+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),
+ language,
+ };
+}
+
+/** Each attribution a text writes: the name it gives a claim to, and where. */
+function attributionsIn(text, language = null) {
+ const found = [];
+ for (const re of attributionsFor(language)) {
+ for (const match of String(text).matchAll(re)) {
+ const name = match.groups?.name ?? '';
+ if (name) found.push({ name, index: match.index + match[0].indexOf(name) });
+ }
+ }
+ return found;
+}
+
+/** The names a text gives claims to: the sources the page already attributes to. */
+export function attributedNames(text, language = null) {
+ return attributionsIn(text, language).map((a) => a.name);
+}
+
+/**
+ * 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.
+ */
+function nameStart(name) {
+ for (const word of name.matchAll(/\S+/g)) {
+ const lower = word[0].toLowerCase();
+ if (!NOT_NAMES.has(lower) && !isRole(lower) && !/^\p{L}+ly$/u.test(lower)) return word.index;
+ }
+ return name.length;
+}
+
+/**
+ * Whether a name is one the agent was given (`known`, knownPeople): its own
+ * words (nameStart), without a possessive ("Gartner's latest survey"),
+ * whole or their end of two words at least ("Acme CEO Jane Doe": "Jane
+ * Doe"). "Forrester Research" isn't known for the word "research" in a bio.
+ */
+function knownName(name, known) {
+ const words = name
+ .slice(nameStart(name))
+ .replace(/['’]\p{L}{0,3}$/u, '')
+ .split(/\s+/)
+ .filter(Boolean);
+ for (let i = 0; words.length - i >= (i === 0 ? 1 : 2); i++) {
+ if (isKnown(words.slice(i).join(' '), known)) return true;
+ }
+ return false;
+}
+
+/** How many claims a text gives to a source the agent wasn't given. */
+function attributions(text, known) {
+ return attributionsIn(text, known?.language).filter((a) => !known || !knownName(a.name, known))
+ .length;
+}
+
+/**
+ * Whether a change gives more claims to a source the agent wasn't given than
+ * the passage did (an insert: than none). Given: one the page attributes to
+ * already, an expert from Brief › Your input, an author (`known`).
+ */
+export function addsAttribution(before, words, known = null) {
+ return attributions(words, known) > attributions(before, known);
+}
+
+/**
+ * A text with each claim given to a source the agent wasn't given put as a
+ * placeholder ("According to [source], …"): for a page rewritten whole,
+ * 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)}`;
+ }
+ return out;
+}
+
+// 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 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');
+
+/**
+ * Whether a replace drops a name from a list the passage has: a product, a
+ * brand or a person left out of a claim changes the claim (editor test
+ * 2026-10-25: Claude dropped from the engines a tool tracks). Only names in
+ * a list: a capitalised word alone may be any noun (German), an acronym or a
+ * 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.
+ */
+export function dropsName(passageText, before, words, rules = [], blocksText = '') {
+ if (rules.includes('bannedWords') || rules.includes('aiTraces')) return false;
+ const text = String(passageText);
+ const changed = knownPeople(`${text.replace(before, () => words)} ${blocksText}`);
+ for (const list of text.match(NAME_LIST) ?? []) {
+ for (const item of list.match(ITEM_RE) ?? []) {
+ if (!String(before).includes(item)) continue;
+ const last = item
+ .split(/\s+/)
+ .pop()
+ .replace(/['’]\p{L}*$/u, '');
+ if (!isKnown(last, changed)) return true;
+ }
+ }
+ return false;
+}
+
/**
* Whether a replace makes a heading ask more than one question: an FAQ
* question with a fan-out's question added to it ("What is X? What is an
@@ -387,6 +591,10 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
const keepsPlaceholders = sourcing.keepPlaceholders === true;
const known = sourcing.known ?? knownNumbers(...passages.map((p) => p.text));
const people = sourcing.people ?? knownPeople(...passages.map((p) => p.text));
+ // The sources a claim may be given to: the ones the page gives claims to,
+ // 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;
const kept = [];
const seen = new Set();
for (const answer of raw) {
@@ -403,7 +611,10 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
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
+ 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)
? {
id: `insert:${passage.text}:${html}`,
row: {
@@ -443,7 +654,10 @@ export function keepSuggestions(raw, passages, lockedKeys, ruleKeys, links = nul
changed &&
(words.length > 2000 ||
growsPastLimit(passage, before, words) ||
- asksMoreThanOne(passage, before, words))
+ asksMoreThanOne(passage, before, words) ||
+ addsAttribution(before, words, attributable) ||
+ (!/^h[1-6]$/.test(passage.tag) &&
+ dropsName(passage.text, before, words, rules, textOf(blocks))))
)
continue;
changes = [
@@ -853,6 +1067,7 @@ async function fixWithRun({
todayText(),
);
// The people and quotes it may name: the same words, its data's and the authors' (CE-044).
+ const authors = await authorWords(supabaseAdmin, brand.organization_id);
const people = knownPeople(
htmlText(draft.body_html),
draft.title,
@@ -861,8 +1076,11 @@ async function fixWithRun({
brand.description,
...ruleWords,
...numbered.map(sourceWords),
- ...(await authorWords(supabaseAdmin, brand.organization_id)),
+ ...authors,
);
+ // 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);
// 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 =
@@ -922,7 +1140,7 @@ async function fixWithRun({
lockedKeys,
ruleKeys,
linkAllowList(targets),
- { numbered, known, people, keepPlaceholders: handoff },
+ { numbered, known, people, attributable, keepPlaceholders: handoff },
);
// 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 51de00a41..acae32ce5 100644
--- a/server/src/lib/content-agent.test.js
+++ b/server/src/lib/content-agent.test.js
@@ -74,6 +74,11 @@ const {
buildFixPrompt,
cleanInsertHtml,
draftPassages,
+ addsAttribution,
+ attributableSources,
+ attributedNames,
+ dropsName,
+ placeholderAttributions,
dropsPlaceholder,
emptyWhy,
fixDraftRules,
@@ -257,6 +262,266 @@ describe('keepSuggestions', () => {
]);
});
+ it('keeps no claim given to a source, nor a change that drops a name (editor test 2026-10-25)', () => {
+ const listed = [
+ {
+ tag: 'p',
+ text: 'Ansvisor, Profound and LLM Pulse track ChatGPT, Gemini and Claude.',
+ },
+ ];
+ const change = (after, rules = ['dated']) =>
+ suggestion({
+ passage: 1,
+ before: 'Ansvisor, Profound and LLM Pulse track ChatGPT, Gemini and Claude',
+ after,
+ rules,
+ sources: [],
+ marks: [],
+ });
+ const kept = (s) =>
+ keepSuggestions([s], listed, new Set(), new Set(['dated', 'bannedWords']), null, sourcing);
+ // An AI Overview's claim given to Zapier, and Claude dropped: neither kept.
+ expect(
+ kept(
+ change(
+ 'According to Zapier, Ansvisor, Profound and LLM Pulse track ChatGPT, Gemini and Claude',
+ ),
+ ),
+ ).toEqual([]);
+ expect(kept(change('Ansvisor, Profound and LLM Pulse track ChatGPT and Gemini'))).toEqual([]);
+ // Every name kept, no source made up: kept.
+ expect(
+ kept(change('Ansvisor, Profound and LLM Pulse each track ChatGPT, Gemini and Claude')),
+ ).toHaveLength(1);
+ // A banned word taken out may go.
+ expect(
+ kept(change('Ansvisor, Profound and LLM Pulse track ChatGPT and Gemini', ['bannedWords'])),
+ ).toHaveLength(1);
+ // An insert that gives a claim to a source it wasn't given isn't kept either.
+ expect(
+ kept(
+ suggestion({
+ kind: 'insert',
+ passage: 1,
+ before: '',
+ after: '<p>According to Zapier, these tools cover every engine.</p>',
+ rules: ['dated'],
+ sources: [],
+ marks: [],
+ }),
+ ),
+ ).toEqual([]);
+ });
+
+ it('reads attributions in English, German and Turkish, and the names past a sentence’s first word', () => {
+ expect(addsAttribution('Teams forecast.', 'According to Gartner, teams forecast.')).toBe(true);
+ expect(addsAttribution('Teams forecast.', 'Gartner found that teams forecast.')).toBe(true);
+ expect(addsAttribution('Teams forecast.', 'Laut Gartner prognostizieren Teams.')).toBe(true);
+ expect(addsAttribution('Teams forecast.', 'Teams prognostizieren, laut Gartner.')).toBe(true);
+ expect(addsAttribution('Ekipler tahmin eder.', "Gartner'a göre ekipler tahmin eder.")).toBe(
+ true,
+ );
+ // One the passage had already: none added.
+ expect(
+ addsAttribution('According to Gartner, teams forecast.', 'According to Gartner, teams plan.'),
+ ).toBe(false);
+ // "The report says" names no one.
+ expect(addsAttribution('Teams forecast.', 'The report says teams forecast.')).toBe(false);
+ // One the agent was given (an expert from Your input, a brand the page names) may be.
+ expect(
+ addsAttribution(
+ 'Teams forecast.',
+ 'Ada Lovelace says teams forecast.',
+ knownPeople('Ada Lovelace, head of data'),
+ ),
+ ).toBe(false);
+ // "As Zapier says": the name is Zapier, known when the page gives claims to it.
+ expect(
+ addsAttribution('Teams forecast.', 'As Zapier says, teams forecast.', knownPeople('Zapier')),
+ ).toBe(false);
+ // More ways to give a claim to a source.
+ expect(addsAttribution('', 'According to the Zapier report, teams forecast.')).toBe(true);
+ expect(addsAttribution('', 'According to a 2025 Gartner survey, teams forecast.')).toBe(true);
+ expect(addsAttribution('', "Gartner's research shows teams forecast.")).toBe(true);
+ });
+
+ // A replace of the whole passage: its words before and after.
+ const drops = (before, words, rules, blocks) => dropsName(before, before, words, rules, blocks);
+
+ it('reads a dropped name only in a list: any capitalised word may be a noun, an acronym or a month', () => {
+ expect(
+ drops('Ansvisor tracks ChatGPT, Gemini and Claude.', 'Ansvisor tracks ChatGPT and Gemini.'),
+ ).toBe(true);
+ expect(drops('Teams use Ansvisor daily.', 'Teams use it daily.')).toBe(false);
+ expect(drops('Most AI search tools track it.', 'Most answer engines track it.')).toBe(false);
+ expect(drops('Funktionen für Marketing Teams im März.', 'Werkzeuge für Marketing-Teams.')).toBe(
+ false,
+ );
+ // Taken out for a banned word: it may.
+ expect(
+ drops('Track ChatGPT, Gemini and Claude.', 'Track ChatGPT and Gemini.', ['bannedWords']),
+ ).toBe(false);
+ });
+
+ it('keeps a change that keeps every name, worded or cased another way', () => {
+ // An item read by its last word, in any case.
+ expect(
+ drops('Ask ChatGPT, Gemini or Claude for one.', 'When you ask ChatGPT, Gemini or Claude…'),
+ ).toBe(false);
+ // A possessive or a case ending moved.
+ expect(
+ drops(
+ 'Compare ChatGPT, Gemini and Claude’s answers.',
+ 'Compare the answers from ChatGPT, Gemini and Claude.',
+ ),
+ ).toBe(false);
+ expect(drops("ChatGPT, Gemini ve Claude'u izler.", "ChatGPT, Gemini ve Claude'da izler.")).toBe(
+ false,
+ );
+ // A list ending its sentence, and a change going on after its last name.
+ expect(
+ drops(
+ 'It works with Shopify, WooCommerce and Magento.',
+ 'It works with Shopify, WooCommerce and Magento in five minutes.',
+ ),
+ ).toBe(false);
+ // A list turned into bullets: the names are in the blocks added.
+ expect(
+ drops(
+ 'Track ChatGPT, Gemini and Claude.',
+ 'Track these engines:',
+ [],
+ 'ChatGPT Gemini Claude',
+ ),
+ ).toBe(false);
+ });
+
+ it('reads a name dropped through a short replace, in the passage as changed', () => {
+ const passage = 'Ansvisor tracks ChatGPT, Gemini and Claude.';
+ expect(dropsName(passage, 'Gemini and Claude', 'Gemini')).toBe(true);
+ expect(dropsName(passage, 'Gemini and Claude', 'Gemini and Claude too')).toBe(false);
+ // Items the replace doesn't touch stay as they are.
+ expect(dropsName(passage, 'Ansvisor tracks', 'It tracks')).toBe(false);
+ });
+
+ it('ends a name at its sentence: the next sentence’s first word isn’t part of it', () => {
+ expect(
+ attributedNames('Teams forecast weekly, according to Gartner. The plan is monthly.'),
+ ).toEqual(['Gartner']);
+ expect(attributedNames('Built on Node.js, according to the U.S Census.')).toEqual([
+ 'U.S Census',
+ ]);
+ const known = knownPeople('According to Gartner, teams forecast.');
+ expect(
+ addsAttribution(
+ 'Teams forecast weekly.',
+ 'Teams forecast weekly, according to Gartner. Most plan monthly.',
+ known,
+ ),
+ ).toBe(false);
+ expect(
+ placeholderAttributions('Teams forecast, according to Zapier. The plan is monthly.', known),
+ ).toBe('Teams forecast, according to [source]. The plan is monthly.');
+ expect(
+ drops(
+ 'Ansvisor tracks ChatGPT, Gemini and Claude. Each answer counts.',
+ 'Ansvisor tracks ChatGPT, Gemini and Claude, so you see each answer.',
+ ),
+ ).toBe(false);
+ });
+
+ it('reads no attribution in "per" before a noun, "claims" or "states" as nouns, or a comparison with "göre"', () => {
+ 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);
+ // The attributions themselves still are.
+ expect(addsAttribution('', 'Per Gartner, teams forecast.')).toBe(true);
+ expect(addsAttribution('', "Per Gartner's survey, teams forecast.")).toBe(true);
+ expect(addsAttribution('', 'Teams forecast weekly, per Gartner.')).toBe(true);
+ expect(addsAttribution('', 'Gartner claims that teams forecast.')).toBe(true);
+ expect(addsAttribution('', "Gartner'a göre ekipler tahmin eder.")).toBe(true);
+ });
+
+ it('knows a source named with a role or an adverb before it, and its end of two words', () => {
+ const known = knownPeople('Jane Doe', 'According to Gartner, teams forecast.');
+ expect(addsAttribution('', 'Acme CEO Jane Doe says that teams forecast.', known)).toBe(false);
+ expect(addsAttribution('', 'CEO Jane Doe says teams forecast.', known)).toBe(false);
+ expect(addsAttribution('', 'Recently Gartner said that teams forecast.', known)).toBe(false);
+ expect(placeholderAttributions('CEO Jane Doe says teams forecast.', known)).toBe(
+ 'CEO Jane Doe says teams forecast.',
+ );
+ });
+
+ it('puts only the name as a placeholder: the word a sentence starts with stays', () => {
+ const known = knownPeople('According to Gartner, teams forecast.');
+ expect(placeholderAttributions('As Zapier says, teams forecast.', known)).toBe(
+ 'As [source] says, teams forecast.',
+ );
+ expect(placeholderAttributions('While Zapier says that teams forecast, …', known)).toBe(
+ 'While [source] says that teams forecast, …',
+ );
+ expect(placeholderAttributions('According to the U.S. Census Bureau, most do.', known)).toBe(
+ 'According to the [source], most do.',
+ );
+ expect(attributedNames('According to the U.S. Census Bureau, most do.')).toEqual([
+ 'U.S. Census Bureau',
+ ]);
+ });
+
+ it('reads "per" as an attribution on an English page only', () => {
+ const german = attributableSources('<p>Wir planen.</p>', [], [], 'de');
+ expect(addsAttribution('', 'Per E-Mail, Telefon oder Chat erreichen Sie uns.', german)).toBe(
+ false,
+ );
+ expect(addsAttribution('', 'Sie erreichen uns telefonisch, per E-Mail.', german)).toBe(false);
+ expect(placeholderAttributions('Kontaktieren Sie uns telefonisch, per E-Mail.', german)).toBe(
+ 'Kontaktieren Sie uns telefonisch, per E-Mail.',
+ );
+ // "laut" is German's.
+ expect(addsAttribution('', 'Laut Gartner planen Teams.', german)).toBe(true);
+ const english = attributableSources('<p>Teams plan.</p>', [], [], 'en');
+ expect(addsAttribution('', 'Per Gartner, teams plan.', english)).toBe(true);
+ // An acronym may be a source too ("Per IDC, …"): "Per SKU, …" reads as one.
+ expect(addsAttribution('', 'Per SKU, you pay once.', english)).toBe(true);
+ });
+
+ it('reads a long run of capitals quickly', () => {
+ const started = Date.now();
+ addsAttribution('', `According to ${'A'.repeat(20000)} says that.`);
+ const list = `${'B'.repeat(20000)}, C and D`;
+ dropsName(list, list, 'C and D');
+ expect(Date.now() - started).toBeLessThan(500);
+ });
+
+ 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(
+ addsAttribution('', "According to Gartner's latest survey, teams forecast.", known),
+ ).toBe(false);
+ expect(addsAttribution('', 'According to Forrester Research, teams forecast.', known)).toBe(
+ true,
+ );
+ expect(addsAttribution('', 'As Gartner says, teams forecast.', known)).toBe(false);
+ });
+
+ it('puts a claim given to a source it wasn’t given as a placeholder, and reads the page’s own', () => {
+ const known = attributableSources(
+ '<p>According to Gartner, teams forecast weekly.</p><p>Zapier, Make and n8n run it.</p>',
+ [{ kind: 'input', ref: 'i1', label: 'Ada Lovelace, head of data', detail: '' }],
+ ['Grace Hopper'],
+ );
+ expect(
+ placeholderAttributions('According to Gartner, most do. According to Zapier, all do.', known),
+ ).toBe('According to Gartner, most do. According to [source], all do.');
+ // Listed by the page, not given claims by it: Zapier isn't one to give a claim to.
+ expect(addsAttribution('', 'Zapier says teams forecast.', known)).toBe(true);
+ expect(addsAttribution('', 'Ada Lovelace says teams forecast.', known)).toBe(false);
+ expect(addsAttribution('', 'Grace Hopper says teams forecast.', known)).toBe(false);
+ });
+
it('keeps no number without a source (CE-033)', () => {
// A figure in none of the data: not kept, even marked to a source.
const invented = { after: '87% of baristas use freshly ground coffee' };
diff --git a/server/src/lib/content-people.js b/server/src/lib/content-people.js
index 0460110f8..e53c68a44 100644
--- a/server/src/lib/content-people.js
+++ b/server/src/lib/content-people.js
@@ -235,7 +235,8 @@ const ROLE_TR = new RegExp(
`^(?:${[...ROLE_WORDS_TR, ...TITLE_WORDS_TR].join('|')})${TR_ANY}$`,
'u',
);
-const isRole = (lower) => ROLE_SET.has(lower) || ROLE_TR.test(lower) || TITLE_NOUNS.has(lower);
+export const isRole = (lower) =>
+ ROLE_SET.has(lower) || ROLE_TR.test(lower) || TITLE_NOUNS.has(lower);
/** No title word next, as the first word after a role ("Yönetici Paneli Giriş Sayfası"). */
const NOT_TITLE_NEXT = `(?!(?:${[...TITLE_NOUNS].map(eitherCase).join('|')})(?!\\p{L}))`;
@@ -391,7 +392,7 @@ const NAME_CUES = [
];
/** Capitalised words that start a sentence, not a name ("The team said", "As Ada says"). */
-const NOT_NAMES = new Set(
+export const NOT_NAMES = new Set(
(
'the this that these those our your their his her its a an every each some most many one we they it ' +
'as when if but and so then while because after before like unlike for in on at by with from to of ' +
diff --git a/server/src/lib/content-rewrite.js b/server/src/lib/content-rewrite.js
index 27946ec3e..60ed6f3b2 100644
--- a/server/src/lib/content-rewrite.js
+++ b/server/src/lib/content-rewrite.js
@@ -62,6 +62,7 @@ How to rewrite:
- Meet every rule listed, and the writer's own rules. Aim at the Length given: the page's whole text, kept blocks included, within 20% of it. When the page is too long, cut repetition, filler and the least useful parts first, and keep its answers, facts and data.
- Keep the page's facts and voice. Use only facts from the page, the brand, the brief and your data. Never invent numbers, prices, dates, names, customers, sources or quotes; when the page needs a fact you don't have, write a placeholder in square brackets, e.g. [figure, source, year]. A number that isn't in them becomes a placeholder.
- Put the numbers (S1, S2…) of the data the page uses in "sources".
+- Never give a claim to a source that neither the page nor Your input gives ("According to X…", "X says…"): you don't see what a cited page or a link says. Keep every name the page has (a product, a brand, a person) where it lists or claims it.
- One H1, the page's title, first. Sections are H2s; questions and sub-sections are H3s.
- Answer first: under each heading, a short paragraph that answers it, then the detail.
- Headings are one short line: an H1 up to ${HEADING_LIMITS.h1} characters, others up to ${HEADING_LIMITS.other}. Never put a sentence or an answer in a heading.
diff --git a/server/src/lib/content-writer.js b/server/src/lib/content-writer.js
index db96600d6..3e6689460 100644
--- a/server/src/lib/content-writer.js
+++ b/server/src/lib/content-writer.js
@@ -4,6 +4,9 @@ import { z } from 'zod';
import supabaseAdmin from '../config/supabase.js';
import { resolveModel } from './ai-provider.js';
import {
+ ATTRIBUTION_RULE,
+ attributableSources,
+ placeholderAttributions,
FANOUT_RULE,
HEADING_RULE,
LINK_RULE,
@@ -164,6 +167,7 @@ ${FANOUT_RULE}
- Put the keys of the rules a change meets in "rules" (none when it meets none).
- Use only facts from the page, the brand and your data. Never invent numbers, prices, dates, names, sources or quotes; write a placeholder in square brackets instead, e.g. [figure, source, year].
${SOURCES_RULE}
+${ATTRIBUTION_RULE}
- Keep the page's voice. The most useful changes first, at most ${MAX_AGENT_SUGGESTIONS}.
- "reason" says in a few words what the change does, e.g. "answer the search 'x' (fan-out)".
- Write in the language asked for.`;
@@ -530,6 +534,7 @@ async function letGo(draft) {
* leaves no page, fails the run. The draft's status doesn't change.
*/
async function rewritePage({
+ attributable,
draft,
brand,
model,
@@ -582,7 +587,8 @@ async function rewritePage({
// blockquotes too, before what it kept goes back, so the page's own
// passages are never touched.
const cleaned = cleanPageHtml(
- guardPeopleInHtml(answer.html, people).html,
+ // A claim given to a source it wasn't given: a placeholder, not the page dropped.
+ placeholderAttributions(guardPeopleInHtml(answer.html, people).html, attributable),
rewriteLinks(draft.body_html, linkAllowList(targets)),
{ h1Kept: page.h1Token !== null, originalH1: page.h1 },
);
@@ -837,6 +843,7 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
);
const knownInPage = new Set([...known, ...knownNumbers(...numbered.map(sourceWords))]);
// The people and quotes it may name: the same words, its data's and the authors' (CE-044).
+ const authors = await authorWords(supabaseAdmin, brand.organization_id);
const people = knownPeople(
htmlText(draft.body_html),
draft.title,
@@ -847,11 +854,15 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
...input.rules.flatMap((r) => [r.name, r.detail]),
...input.textRules,
...numbered.map(sourceWords),
- ...(await authorWords(supabaseAdmin, brand.organization_id)),
+ ...authors,
);
+ // 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);
if (rewrite) {
return await rewritePage({
+ attributable,
draft,
brand,
model,
@@ -946,7 +957,7 @@ async function writeWithRun({ draft, brand, model, input, budget, rewrite, run }
lockedKeys,
ruleKeys,
linkAllowList(targets),
- { numbered, known, people },
+ { numbered, known, people, attributable },
);
// Stopped meanwhile: nothing it wrote is kept.
await stopIfStopped(run);