Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(content): count the claims in the page's own words in Trust and underline the unsourced ones (CE-045, part b) (#1458)

Cihand2a734303ff9
diff --git a/web/messages/en.json b/web/messages/en.json
index 2763285b2..74e2c6b5d 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -4542,6 +4542,7 @@
"otherDetail": "Check what your CMS adds for it (Product, ItemList…). The code Ansvisor gives here is for articles."
},
"linksPending": "Still reading {count, plural, one {# of the page's links} other {# of the page's links}}, so Trust may change.",
+ "claimsReading": "Still reading the claims in your own words, so Trust may change.",
"datesNote": "The dates are today's: change them if the page goes out on another day.",
"headlineLeftOut": "The title still has a placeholder in square brackets, so the code leaves the headline out. Fill it in, and the headline comes back here.",
"states": {
@@ -4712,6 +4713,13 @@
"addInput": "Add",
"keep": "Keep",
"aiCheck": "AI check",
+ "addSource": "Add source",
+ "addSourceTo": "Add a source to “{claim}”",
+ "remove": "Remove",
+ "removeClaim": "Remove “{sentence}” from the page",
+ "claimNoSource": "No source for this claim. Add a source, or take it out. Content Agent will not make one up.",
+ "claimsPaused": "Claims in your own words wait for an AI check: this month's AI usage is used up. They're read again when it renews.",
+ "claimsLimited": "Today's AI checks of this page's claims are used up. Paragraphs you change now are checked when you open the page again tomorrow.",
"aiPaused": "Sources the rules can't place wait for an AI check: this month's AI usage is used up. They count again when it renews.",
"keepFailed": "Couldn't keep the source. Try again.",
"keepFull": "This page keeps 50 sources already: replace one instead.",
@@ -4726,7 +4734,9 @@
"checks": {
"claimsSourced": {
"line": "{count, plural, one {# sentence with a figure has} other {# sentences with figures have}} no source",
- "detail": "Link each figure's source in the same paragraph, or take the figure out. Content Agent won't make one up."
+ "detail": "Link each figure's source in the same paragraph, or take the figure out. Content Agent won't make one up.",
+ "lineClaims": "{count, plural, one {# claim has} other {# claims have}} no source",
+ "detailClaims": "Figures, findings, superlatives, awards and product facts: link each one's source in the same paragraph, or take it out. Content Agent won't make one up."
},
"freshSources": {
"line": "{count} of {total} dated {total, plural, one {source} other {sources}} {count, plural, one {is} other {are}} over {months} months old",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx
index 62caf2197..e3993e59d 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx
@@ -147,6 +147,8 @@ const trustRead = (over: Partial<TrustRead>): TrustRead => ({
dated: 0,
unsourced: [],
figures: 0,
+ marks: [],
+ aiClaims: 0,
weak: [],
classified: 0,
...over,
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx
index 4450db2dd..13b2da597 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.tsx
@@ -212,6 +212,11 @@ export function BeforePublish({
{t('linksPending', { count: linksPending })}
</p>
)}
+ {quality.claimsReading && (
+ <p role="status" className="text-xs text-muted-foreground">
+ {t('claimsReading')}
+ </p>
+ )}
<ul className="divide-y rounded-xl border text-sm">
{rows.map((row) => (
<li key={row.title} className="flex items-start gap-2.5 px-3 py-2.5">
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_claim-marks.test.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_claim-marks.test.ts
new file mode 100644
index 000000000..b54eb5e80
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_claim-marks.test.ts
@@ -0,0 +1,130 @@
+import { Editor } from '@tiptap/core';
+import { TableKit } from '@tiptap/extension-table';
+import StarterKit from '@tiptap/starter-kit';
+import { afterEach, describe, expect, it } from 'vitest';
+import { trustBlocks } from '@/lib/content/quality-checks';
+import { ClaimMarksExtension, claimMarksKey, textRanges, writingBlock } from './_claim-marks';
+
+let editor: Editor | null = null;
+afterEach(() => {
+ editor?.destroy();
+ editor = null;
+});
+
+const open = (content: string) => {
+ editor?.destroy();
+ editor = new Editor({
+ extensions: [
+ StarterKit,
+ TableKit.configure({ table: { resizable: false } }),
+ ClaimMarksExtension,
+ ],
+ content,
+ });
+ return editor;
+};
+const words = (e: Editor, { from, to }: { from: number; to: number }) =>
+ e.state.doc.textBetween(from, to);
+
+/** Claims with no source (Quality CE-045): found by their words, underlined in the draft. */
+describe('textRanges', () => {
+ it('finds a text in its block, across bold and links, each time it is there', () => {
+ const e = open(
+ '<h1>Title</h1><p>Ledgerly is <strong>the fastest</strong> app. Ledgerly is the fastest app.</p>',
+ );
+ const ranges = textRanges(e.state.doc, 'the fastest app');
+ expect(ranges).toHaveLength(2);
+ for (const range of ranges) expect(words(e, range)).toBe('the fastest app');
+ // Not across two blocks.
+ expect(textRanges(open('<p>the fastest</p><p>app</p>').state.doc, 'the fastest app')).toEqual(
+ [],
+ );
+ });
+
+ it("finds Trust's words where the page has no space: a link's edge, a line break, a no-break space", () => {
+ const html =
+ '<p>Teams save 40<strong>%</strong> (<a href="https://x.example">report</a>).</p>' +
+ '<p>First line<br>SOC 2\u00a0certified plans.</p>';
+ const e = open(html);
+ const [first, second] = trustBlocks(html).map((b) => b.text);
+ // As Trust reads them: "40 %", "( report)", the break and the no-break space a space.
+ expect(first).toBe('Teams save 40 % ( report).');
+ expect(second).toBe('First line SOC 2 certified plans.');
+ const [a] = textRanges(e.state.doc, first, first);
+ expect(words(e, a)).toBe('Teams save 40% (report).');
+ const [b] = textRanges(e.state.doc, 'line SOC 2 certified', second);
+ expect(words(e, b)).toBe('lineSOC 2\u00a0certified');
+ });
+
+ it("looks in the claim's block only, never in a heading", () => {
+ const html =
+ '<h2>Why Ledgerly is the fastest forecasting app</h2>' +
+ '<p>Ledgerly is the fastest forecasting app, <a href="https://g2.example">G2</a> says.</p>' +
+ '<p>Ledgerly is the fastest forecasting app for small teams.</p>';
+ const e = open(html);
+ const blocks = trustBlocks(html);
+ const ranges = textRanges(e.state.doc, 'the fastest forecasting app', blocks[1].text);
+ expect(ranges).toHaveLength(1);
+ // The third paragraph's, not the heading's or the sourced one's.
+ expect(e.state.doc.resolve(ranges[0].from).parent.textContent).toContain('small teams');
+ // A list item's own words hold its paragraph, not its nested list's.
+ const list = '<ul><li><p>Rated #1 by G2.</p><ul><li><p>Rated #1 by G2.</p></li></ul></li></ul>';
+ const inList = open(list);
+ expect(textRanges(inList.state.doc, 'Rated #1', trustBlocks(list)[0].text)).toHaveLength(2);
+ });
+});
+
+describe('writingBlock', () => {
+ const at = (e: Editor, text: string) => {
+ let pos = -1;
+ e.state.doc.descendants((node, p) => {
+ if (pos === -1 && node.isText && node.text?.includes(text)) pos = p + 1;
+ });
+ e.commands.setTextSelection(pos);
+ return writingBlock(e);
+ };
+
+ it("reads the cursor's block as Trust does: a paragraph, a list item, a quote, a cell", () => {
+ const html =
+ '<h2>A heading</h2><p>Teams save <strong>40</strong>% (<a href="https://x.example">report</a>).</p>' +
+ '<ul><li><p>Outer item</p><ul><li><p>Inner item</p></li></ul></li></ul>' +
+ '<blockquote><p>Rated #1.</p><p>Loved by users.</p></blockquote>' +
+ '<table><tbody><tr><td><p>Clinically tested</p></td><td><p>Other cell</p></td></tr></tbody></table>';
+ const e = open(html);
+ const blocks = trustBlocks(e.getHTML()).map((b) => b.text);
+ expect(at(e, 'Teams save')).toBe(blocks[0]);
+ expect(at(e, 'Outer item')).toBe('Outer item');
+ expect(at(e, 'Inner item')).toBe('Inner item');
+ expect(at(e, 'Loved by')).toBe('Rated #1. Loved by users.');
+ expect(at(e, 'Clinically')).toBe('Clinically tested');
+ expect(blocks).toEqual(
+ expect.arrayContaining(['Outer item', 'Rated #1. Loved by users.', 'Clinically tested']),
+ );
+ // Not Trust's: nothing to leave for later.
+ expect(at(e, 'A heading')).toBeNull();
+ });
+});
+
+describe('ClaimMarksExtension', () => {
+ it('underlines each claim in its block with why on hover, and moves the marks as the page changes', () => {
+ const e = open('<h2>SOC 2 certified</h2><p>Every plan is SOC 2 certified.</p>');
+ const mark = {
+ text: 'SOC 2 certified',
+ sentence: 'Every plan is SOC 2 certified.',
+ block: 'Every plan is SOC 2 certified.',
+ };
+ e.view.dispatch(e.state.tr.setMeta(claimMarksKey, { marks: [mark], title: 'No source.' }));
+ const found = claimMarksKey.getState(e.state)!.decorations.find();
+ expect(found).toHaveLength(1);
+ expect(words(e, found[0])).toBe('SOC 2 certified');
+ expect(e.view.dom.querySelector('h2 [title]')).toBeNull();
+ expect(e.view.dom.querySelector('p [title="No source."]')?.textContent).toBe('SOC 2 certified');
+ // Typing before it moves the mark with the words.
+ e.commands.insertContentAt(e.state.doc.child(0).nodeSize + 1, 'Now ');
+ const moved = claimMarksKey.getState(e.state)!.decorations.find();
+ expect(words(e, moved[0])).toBe('SOC 2 certified');
+ // An empty list clears them.
+ e.view.dispatch(e.state.tr.setMeta(claimMarksKey, { marks: [], title: '' }));
+ expect(claimMarksKey.getState(e.state)!.decorations.find()).toEqual([]);
+ });
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_claim-marks.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_claim-marks.ts
new file mode 100644
index 000000000..4b34f1e4a
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_claim-marks.ts
@@ -0,0 +1,135 @@
+import { Extension, getHTMLFromFragment, type Editor } from '@tiptap/core';
+import { Fragment, type Node as PmNode } from '@tiptap/pm/model';
+import { Plugin, PluginKey } from '@tiptap/pm/state';
+import { Decoration, DecorationSet } from '@tiptap/pm/view';
+import { trustBlocks, type ClaimMark } from '@/lib/content/quality-checks';
+
+/**
+ * Claims with no source in the draft (Quality spec §3, CE-045): a red wavy
+ * underline on the claim's words, with why on hover. A decoration, never
+ * the page's, so no save, export, copy or CMS push has it. Quality's
+ * suggestion has Show, Add source and Remove.
+ */
+
+export interface ClaimMarks {
+ /** The claims to underline (trust's marks), each in its block. */
+ marks: readonly ClaimMark[];
+ /** Why, on hover. */
+ title: string;
+}
+
+interface ClaimState extends ClaimMarks {
+ decorations: DecorationSet;
+}
+
+export const claimMarksKey = new PluginKey<ClaimState>('claimMarks');
+
+const CLAIM =
+ 'underline decoration-wavy decoration-red-500 underline-offset-4 dark:decoration-red-400';
+
+const squeeze = (text: string) => text.replace(/\s+/g, '');
+
+/**
+ * Where a text is in the page, as document positions: each place it is in
+ * a paragraph that holds it whole and, with `block`, is part of that Trust
+ * block (its text, as trustBlocks reads it). Headings and code aren't
+ * Trust's. Spaces don't count: Trust's text has one at each tag's edge
+ * ("( report)", "40 %") and at a line break, where the page may have none.
+ * Its words may run across marks (a bold word, a link), not across blocks.
+ */
+export function textRanges(
+ doc: PmNode,
+ text: string,
+ block?: string,
+): { from: number; to: number }[] {
+ const needle = squeeze(text);
+ if (!needle) return [];
+ const within = block === undefined ? null : squeeze(block);
+ const ranges: { from: number; to: number }[] = [];
+ doc.descendants((node, pos) => {
+ if (!node.isTextblock) return true;
+ if (node.type.name === 'heading' || node.type.spec.code) return false;
+ // The paragraph's words without their spaces, each at its position.
+ let words = '';
+ const at: number[] = [];
+ node.forEach((child, offset) => {
+ const own = child.isText ? (child.text ?? '') : '';
+ for (let i = 0; i < own.length; i++) {
+ if (/\s/.test(own[i])) continue;
+ words += own[i];
+ at.push(pos + 1 + offset + i);
+ }
+ });
+ if (!words || (within !== null && !within.includes(words))) return false;
+ for (let i = words.indexOf(needle); i !== -1; i = words.indexOf(needle, i + 1)) {
+ ranges.push({ from: at[i], to: at[i + needle.length - 1] + 1 });
+ }
+ return false;
+ });
+ return ranges;
+}
+
+const CELLS = new Set(['tableCell', 'tableHeader']);
+const HOLDERS = new Set(['listItem', 'taskItem', 'blockquote']);
+
+/**
+ * The text of the Trust block the cursor is in, as trustBlocks reads it
+ * from the block as it saves: the one the claims' ask leaves for later
+ * (the API hashes it as it does the page's). Null in a heading or code,
+ * which Trust doesn't read.
+ */
+export function writingBlock(editor: Editor): string | null {
+ const { $from } = editor.state.selection;
+ // A cell holds all that's in it; else a list item or a quote holds its paragraphs.
+ let depth = $from.depth;
+ const holder = (names: Set<string>) => {
+ for (let d = $from.depth; d > 0; d--) if (names.has($from.node(d).type.name)) return d;
+ return -1;
+ };
+ const cell = holder(CELLS);
+ const held = cell !== -1 ? cell : holder(HOLDERS);
+ if (held !== -1) depth = held;
+ const node = $from.node(depth);
+ const html = getHTMLFromFragment(Fragment.from(node), editor.schema);
+ // A cell is read only in its table.
+ const page = CELLS.has(node.type.name) ? `<table><tbody><tr>${html}</tr></tbody></table>` : html;
+ return trustBlocks(page)[0]?.text ?? null;
+}
+
+function decorate(doc: PmNode, { marks, title }: ClaimMarks): DecorationSet {
+ if (!marks.length) return DecorationSet.empty;
+ const decorations = marks.flatMap((mark) =>
+ textRanges(doc, mark.text, mark.block).map(({ from, to }) =>
+ Decoration.inline(from, to, { class: CLAIM, title }),
+ ),
+ );
+ return DecorationSet.create(doc, decorations);
+}
+
+export const ClaimMarksExtension = Extension.create({
+ name: 'claimMarks',
+
+ addProseMirrorPlugins() {
+ return [
+ new Plugin<ClaimState>({
+ key: claimMarksKey,
+ state: {
+ init: () => ({ marks: [], title: '', decorations: DecorationSet.empty }),
+ // Marked again when the list changes (the page read after typing
+ // pauses), and mapped through each change meanwhile: a claim
+ // being written over moves with the words around it.
+ apply: (tr, prev) => {
+ const next = tr.getMeta(claimMarksKey) as ClaimMarks | undefined;
+ if (next) return { ...next, decorations: decorate(tr.doc, next) };
+ return tr.docChanged
+ ? { ...prev, decorations: prev.decorations.map(tr.mapping, tr.doc) }
+ : prev;
+ },
+ },
+ props: {
+ decorations: (state) => claimMarksKey.getState(state)?.decorations ?? null,
+ },
+ }),
+ ];
+ },
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
index 23515d8ab..0a01697a1 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
@@ -103,6 +103,7 @@ import {
trust,
trustBlocks,
unplacedSites,
+ type ClaimMark,
} from '@/lib/content/quality-checks';
import { qualityTodos } from '@/lib/content/quality-todos';
import { readability } from '@/lib/content/readability';
@@ -153,6 +154,8 @@ import { OwnCopies, ownCopyHtml } from './_own-copies';
import { NextNudge, useNextNudge } from './_next-nudge';
import { PageInfoStrip, pageInfoKey } from './_page-info';
import { WeakSourcesMarks, weakSourcesKey } from './_weak-sources';
+import { ClaimMarksExtension, claimMarksKey, textRanges, writingBlock } from './_claim-marks';
+import { useClaims } from './_use-claims';
import { useSourceClasses } from './_use-source-classes';
import { HeaderTip } from './_header-tip';
import { NextStepButton, readSkips, wordsUnderTitle, writeSkips } from './_next-step';
@@ -232,6 +235,16 @@ async function agentBatch(draftId: string, until: number): Promise<DraftSuggesti
return null;
}
+/** What a paragraph Remove empties goes with, when it was all they held (CE-045). */
+const EMPTIED_WITH = new Set([
+ 'listItem',
+ 'taskItem',
+ 'bulletList',
+ 'orderedList',
+ 'taskList',
+ 'blockquote',
+]);
+
/**
* The content editor (Content Editor, CE-004, spec §6): a header with the
* draft's title, page type and method, whether it's saved, and Mark ready;
@@ -255,6 +268,7 @@ async function agentBatch(draftId: string, until: number): Promise<DraftSuggesti
* reject, with the agent bar over it, and Fix open rules with agent asks the
* Content Agent for a new batch (CE-018).
*/
+
export function DraftEditor({
draft,
onAgentStarted,
@@ -405,6 +419,7 @@ export function DraftEditor({
FlashBlock,
PageInfoStrip,
WeakSourcesMarks,
+ ClaimMarksExtension,
],
content: draft.bodyHtml,
// Rendered on the client only, so the server's HTML can't disagree with it.
@@ -583,6 +598,25 @@ export function DraftEditor({
unplaced,
sourcesOn,
);
+ // The claims in the draft's own words, as the model reads them (CE-045):
+ // asked after a save, leaving the block the person is writing in.
+ const claimsRead = useClaims(
+ draft.id,
+ autosave.savedAt,
+ sourcesOn,
+ autosave.state !== 'saved',
+ () => (editor && !editor.isDestroyed && editor.isFocused ? writingBlock(editor) : null),
+ );
+ const { blocks: claimBlocks, recheck: recheckClaims } = claimsRead;
+ // Out of the editor (to Quality, to Before you publish): the block left
+ // for later is read too.
+ useEffect(() => {
+ if (!editor) return;
+ editor.on('blur', recheckClaims);
+ return () => {
+ editor.off('blur', recheckClaims);
+ };
+ }, [editor, recheckClaims]);
const sourceRead = useMemo(
() =>
sourcesOn
@@ -606,10 +640,21 @@ export function DraftEditor({
siteTrust,
quote: used ? used.quote : null,
sources: sourceRead,
+ claims: claimBlocks,
now: Date.now(),
})
: null,
- [qualityOn, pageBlocks, linkChecks, brandDomains, siteTrust, inputsPending, used, sourceRead],
+ [
+ qualityOn,
+ pageBlocks,
+ linkChecks,
+ brandDomains,
+ siteTrust,
+ inputsPending,
+ used,
+ sourceRead,
+ claimBlocks,
+ ],
);
// Their links underlined in the draft, Quality's suggestion naming them.
const weakKey = (trustScore?.weak ?? []).map((w) => w.url).join('\n');
@@ -623,6 +668,61 @@ export function DraftEditor({
.setMeta('addToHistory', false),
);
}, [editor, weakKey, weakTitle]);
+ // The claims with no source (CE-045): the model's in their words, the
+ // figures' in their sentences, underlined in their blocks with phase 2.
+ const claimKey = sourcesOn ? JSON.stringify(trustScore?.marks ?? []) : '[]';
+ const claimTitle = t('quality.claimNoSource');
+ useEffect(() => {
+ if (!editor || editor.isDestroyed) return;
+ const marks = JSON.parse(claimKey) as ClaimMark[];
+ editor.view.dispatch(
+ editor.state.tr
+ .setMeta(claimMarksKey, { marks, title: claimTitle })
+ .setMeta('addToHistory', false),
+ );
+ }, [editor, claimKey, claimTitle]);
+ // Quality's Add source: the claim's words selected, the link dialog open
+ // on them (its Apply links them and comes back to the page).
+ const [linkRequest, setLinkRequest] = useState(0);
+ const addSource = (mark: ClaimMark) => {
+ if (!editor) return;
+ const [range] = textRanges(editor.state.doc, mark.text, mark.block);
+ if (!range) {
+ showInPage(mark.sentence);
+ return;
+ }
+ editor.chain().setTextSelection(range).scrollIntoView().run();
+ setLinkRequest((n) => n + 1);
+ };
+ // Quality's Remove: the claim's sentence out of the page, the space after
+ // it too, and the paragraph (its list item) if that leaves it empty. Undo
+ // brings it back.
+ const removeClaim = (mark: ClaimMark) => {
+ if (!editor) return;
+ const [range] = textRanges(editor.state.doc, mark.sentence, mark.block);
+ if (!range) {
+ showInPage(mark.sentence);
+ return;
+ }
+ editor
+ .chain()
+ .command(({ tr }) => {
+ const next =
+ range.to < tr.doc.content.size ? tr.doc.textBetween(range.to, range.to + 1) : '';
+ tr.delete(range.from, next === ' ' ? range.to + 1 : range.to);
+ const $at = tr.doc.resolve(range.from);
+ if ($at.parent.content.size > 0) return true;
+ let depth = $at.depth;
+ while (depth > 1 && $at.node(depth - 1).childCount === 1) {
+ if (!EMPTIED_WITH.has($at.node(depth - 1).type.name)) break;
+ depth--;
+ }
+ if ($at.node(depth - 1).childCount > 1) tr.delete($at.before(depth), $at.after(depth));
+ return true;
+ })
+ .focus(undefined, { scrollIntoView: false })
+ .run();
+ };
const keepSource = async (url: string) => {
setKeptSources((kept) => (kept.includes(url) ? kept : [...kept, url]));
try {
@@ -687,6 +787,9 @@ export function DraftEditor({
todos,
// Only while a source waits for its read.
aiPaused: aiPaused && unplaced.some((site) => !aiKinds.has(site)),
+ claimsPaused: claimsRead.paused,
+ claimsLimited: claimsRead.limited,
+ claimsReading: claimsRead.reading,
}
: null;
// Quality's Pick author opens the header's menu.
@@ -2463,6 +2566,7 @@ export function DraftEditor({
htmlView={htmlSource !== null}
onToggleHtml={htmlSource === null ? openHtmlView : applyHtmlView}
onAttach={attachments.open}
+ linkRequest={linkRequest}
/>
)}
@@ -2550,6 +2654,8 @@ export function DraftEditor({
yourInput={inputsRead.status === 'off' ? null : inputsRead}
onAddInput={addInput}
onKeepSource={sourcesOn ? (url) => void keepSource(url) : undefined}
+ onAddSource={sourcesOn ? addSource : undefined}
+ onRemoveClaim={sourcesOn ? removeClaim : undefined}
/>
) : (
<EditorPanelRail onOpen={openPanelTab} />
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx
index 4f41784b3..14a430f25 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx
@@ -13,6 +13,7 @@ import {
trustGain,
type EeatCheckId,
type Score,
+ type ClaimMark,
type TrustCheckId,
type TrustRead,
} from '@/lib/content/quality-checks';
@@ -50,6 +51,12 @@ export interface QualityRead {
todos: QualityTodo[];
/** The model's reads of sources wait: the workspace's AI budget is spent (CE-046). */
aiPaused?: boolean;
+ /** The model's reads of the claims wait, for the same reason (CE-045). */
+ claimsPaused?: boolean;
+ /** The draft's claim reads for the day are made (CE-045). */
+ claimsLimited?: boolean;
+ /** Some of the page's claims aren't read yet: Trust may change (CE-045). */
+ claimsReading?: boolean;
}
type ScoreName = 'eeat' | 'trust' | 'readability';
@@ -65,6 +72,8 @@ export interface Suggestion {
show: string | null;
/** The source Keep keeps (CE-046): the person trusts it all the same. */
keep?: string;
+ /** The claim whose words Add source selects to link, and whose sentence Remove takes out (CE-045). */
+ claim?: ClaimMark;
/** Read by AI, not by rules alone: it says so (spec §3, "AI check"). */
ai?: boolean;
}
@@ -83,6 +92,8 @@ export function QualityTab({
onPickAuthor,
onAddInput,
onKeep,
+ onAddSource,
+ onRemove,
}: {
quality: QualityRead;
/** Scrolls the draft to a passage and marks it. */
@@ -95,6 +106,10 @@ export function QualityTab({
onAddInput?: () => void;
/** Keeps a weak source or a competitor's on the page (CE-046). */
onKeep?: (url: string) => void;
+ /** Selects a claim's words and opens the link dialog on them (CE-045). */
+ onAddSource?: (claim: ClaimMark) => void;
+ /** Takes a claim's sentence out of the page (CE-045). */
+ onRemove?: (claim: ClaimMark) => void;
}) {
const t = useTranslations('contentEditor.editor.quality');
const tSite = useTranslations('audit.siteTrust.checks');
@@ -194,25 +209,53 @@ export function QualityTab({
{s.detail}
</p>
</div>
- {s.show !== null && (
- <Button
- variant="outline"
- size="sm"
- className="h-7 shrink-0"
- onClick={() => onShow(s.show!)}
- >
- {t('show')}
- </Button>
- )}
- {s.keep && onKeep && (
- <Button
- variant="ghost"
- size="sm"
- className="h-7 shrink-0"
- onClick={() => onKeep(s.keep!)}
- >
- {t('keep')}
- </Button>
+ {(s.show !== null ||
+ (s.claim && (onAddSource || onRemove)) ||
+ (s.keep && onKeep)) && (
+ <div className="flex shrink-0 flex-col items-end gap-1">
+ {s.show !== null && (
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-7"
+ onClick={() => onShow(s.show!)}
+ >
+ {t('show')}
+ </Button>
+ )}
+ {s.claim && onAddSource && (
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-7"
+ aria-label={t('addSourceTo', { claim: s.claim.text })}
+ onClick={() => onAddSource(s.claim!)}
+ >
+ {t('addSource')}
+ </Button>
+ )}
+ {s.keep && onKeep && (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-7"
+ onClick={() => onKeep(s.keep!)}
+ >
+ {t('keep')}
+ </Button>
+ )}
+ {s.claim && onRemove && (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-7"
+ aria-label={t('removeClaim', { sentence: s.claim.sentence })}
+ onClick={() => onRemove(s.claim!)}
+ >
+ {t('remove')}
+ </Button>
+ )}
+ </div>
)}
</li>
))}
@@ -222,6 +265,10 @@ export function QualityTab({
)}
{quality.aiPaused && <p className="text-xs text-muted-foreground">{t('aiPaused')}</p>}
+ {quality.claimsPaused && <p className="text-xs text-muted-foreground">{t('claimsPaused')}</p>}
+ {quality.claimsLimited && !quality.claimsPaused && (
+ <p className="text-xs text-muted-foreground">{t('claimsLimited')}</p>
+ )}
{siteTrust && (
<section
@@ -441,15 +488,23 @@ export function trustSuggestions(t: T, trust: TrustRead | null): TrustSuggestion
if (!trust) return [];
const out: TrustSuggestion[] = [];
if (trust.unsourced.length) {
+ // Phase 2 (CE-045): claims the model read count with the figures, so
+ // the line says claims; Add source and Remove act on the page's first.
+ const claims = trust.aiClaims > 0;
+ const first = trust.unsourced[0];
out.push({
key: 'trust:claimsSourced',
check: 'claimsSourced',
score: 'trust',
gain: trustGain(trust, ['claimsSourced']),
- line: t('checks.claimsSourced.line', { count: trust.unsourced.length }),
+ line: t(claims ? 'checks.claimsSourced.lineClaims' : 'checks.claimsSourced.line', {
+ count: trust.unsourced.length,
+ }),
count: trust.unsourced.length,
- detail: t('checks.claimsSourced.detail'),
- show: trust.unsourced[0],
+ detail: t(claims ? 'checks.claimsSourced.detailClaims' : 'checks.claimsSourced.detail'),
+ show: first,
+ ai: claims,
+ claim: trust.marks.find((mark) => mark.sentence === first),
});
}
if (trust.stale.length) {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_side-panel.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_side-panel.tsx
index 314f9d630..26bc88ad1 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_side-panel.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_side-panel.tsx
@@ -9,6 +9,7 @@ import type { SiteType } from '@/lib/content/page-types';
import { buildSourceGroups, includedCounts, type DraftSourceKind } from '@/lib/content/sources';
import { formatNumber } from '@/lib/format';
import { BAND_CLASSES, qualityBand, qualityPhase } from '@/lib/content/quality';
+import type { ClaimMark } from '@/lib/content/quality-checks';
import { cn } from '@/lib/utils';
import { BriefTab, type AgentRewrite } from './_brief-tab';
import { DataNote, UsesYourData } from './_data-note';
@@ -132,6 +133,8 @@ export function EditorSidePanel({
yourInput = null,
onAddInput,
onKeepSource,
+ onAddSource,
+ onRemoveClaim,
}: {
draft: ContentDraft;
/** The brand's business type as the editor holds it (Quality CE-056). */
@@ -189,6 +192,10 @@ export function EditorSidePanel({
onAddInput?: () => void;
/** Keeps a weak source or a competitor's on the page (Quality CE-046), once phase 2 is live. */
onKeepSource?: (url: string) => void;
+ /** Selects a claim's words and opens the link dialog on them: Quality's Add source (CE-045). */
+ onAddSource?: (claim: ClaimMark) => void;
+ /** Takes a claim's sentence out of the page: Quality's Remove (CE-045). */
+ onRemoveClaim?: (claim: ClaimMark) => void;
}) {
const t = useTranslations('contentEditor.editor.panel');
const tEditor = useTranslations('contentEditor.editor');
@@ -435,6 +442,8 @@ export function EditorSidePanel({
onPickAuthor={() => onPickAuthor?.()}
onAddInput={onAddInput}
onKeep={onKeepSource}
+ onAddSource={onAddSource}
+ onRemove={onRemoveClaim}
/>
</div>
)}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx
index b27a7bda1..05d0eaf10 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx
@@ -72,6 +72,7 @@ export function EditorToolbar({
htmlView,
onToggleHtml,
onAttach,
+ linkRequest = 0,
}: {
editor: Editor;
target: number;
@@ -80,9 +81,20 @@ export function EditorToolbar({
htmlView: boolean;
onToggleHtml: () => void;
onAttach: () => void;
+ /**
+ * A new number opens the link dialog on the selection: Quality's Add
+ * source, its claim selected (CE-045).
+ */
+ linkRequest?: number;
}) {
const t = useTranslations('contentEditor.editor.toolbar');
const [dialog, setDialog] = useState<'link' | 'image' | 'htmlBlock' | null>(null);
+ // Only a new request opens it: not the toolbar showing again.
+ const [linkAsked, setLinkAsked] = useState(linkRequest);
+ if (linkRequest !== linkAsked) {
+ setLinkAsked(linkRequest);
+ if (linkRequest > 0) setDialog('link');
+ }
// Re-read only what the toolbar shows, not on every keystroke's render.
const state = useEditorState({
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx
new file mode 100644
index 000000000..c5e3ffa32
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx
@@ -0,0 +1,197 @@
+import { act, useEffect } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const checkDraftClaims = vi.fn();
+vi.mock('@/lib/actions/content-drafts', () => ({
+ checkDraftClaims: (...args: unknown[]) => checkDraftClaims(...args),
+}));
+
+const { CLAIMS_DELAY_MS, CLAIMS_EVERY_MS, useClaims } = await import('./_use-claims');
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
+ true;
+
+/**
+ * The claims in the draft's own words (Quality CE-045): asked a few seconds
+ * after a save, no closer than CLAIMS_EVERY_MS, one ask at a time, not with
+ * changes to save, leaving the block being written; a spent AI budget or
+ * the day's reads made stop the asks.
+ */
+
+let container: HTMLDivElement;
+let root: Root;
+let writing: string | null = null;
+let recheck: () => void = () => {};
+
+function Probe({
+ savedAt,
+ enabled = true,
+ unsaved = false,
+}: {
+ savedAt: string;
+ enabled?: boolean;
+ unsaved?: boolean;
+}) {
+ const read = useClaims('d1', savedAt, enabled, unsaved, () => writing);
+ useEffect(() => {
+ recheck = read.recheck;
+ });
+ return (
+ <pre
+ data-blocks={JSON.stringify(read.blocks)}
+ data-paused={String(read.paused)}
+ data-limited={String(read.limited)}
+ data-reading={String(read.reading)}
+ />
+ );
+}
+
+const attr = (name: string) => container.querySelector('pre')!.getAttribute(name)!;
+const blocks = () => JSON.parse(attr('data-blocks'));
+const paused = () => attr('data-paused') === 'true';
+const render = (savedAt: string, enabled = true, unsaved = false) =>
+ act(async () => root.render(<Probe savedAt={savedAt} enabled={enabled} unsaved={unsaved} />));
+const wait = (ms: number) => act(async () => vi.advanceTimersByTimeAsync(ms));
+const BLOCK = {
+ text: 'Ledgerly is the fastest app.',
+ claims: [{ text: 'the fastest app', kind: 'superlative' }],
+};
+
+beforeEach(() => {
+ vi.useFakeTimers();
+ writing = null;
+ checkDraftClaims.mockReset().mockResolvedValue({ blocks: [BLOCK], pending: 0, limited: false });
+ container = document.createElement('div');
+ root = createRoot(container);
+});
+afterEach(() => {
+ act(() => root.unmount());
+ vi.useRealTimers();
+});
+
+describe('useClaims', () => {
+ it('asks a few seconds after a save, leaving the block being written', async () => {
+ writing = 'Still writing this.';
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS - 100);
+ expect(checkDraftClaims).not.toHaveBeenCalled();
+ await wait(100);
+ expect(checkDraftClaims).toHaveBeenCalledWith('d1', 'Still writing this.');
+ expect(blocks()).toEqual([BLOCK]);
+ });
+
+ it('asks no closer together than CLAIMS_EVERY_MS, and once a save', async () => {
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ await render('s1');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ await render('s2');
+ await wait(CLAIMS_DELAY_MS);
+ // Within half a minute of the last ask: not yet.
+ await render('s3');
+ await wait(CLAIMS_DELAY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ });
+
+ it('asks about a save made while an ask is out once it is back', async () => {
+ let answer: (value: unknown) => void = () => {};
+ checkDraftClaims.mockReturnValueOnce(new Promise((resolve) => (answer = resolve)));
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ await render('s2');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ await act(async () => answer({ blocks: [], pending: 0, limited: false }));
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ });
+
+ it('pauses once the AI budget is spent, and stops silently when the API has them off', async () => {
+ checkDraftClaims.mockResolvedValueOnce({ error: 'ai_budget' });
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ expect(paused()).toBe(true);
+ await render('s2');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+
+ act(() => root.unmount());
+ root = createRoot(container);
+ checkDraftClaims.mockReset().mockResolvedValue({ error: 'off' });
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ await render('s2');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ expect(paused()).toBe(false);
+ });
+
+ it('asks again after the next save when an ask fails, not on a timer', async () => {
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
+ checkDraftClaims.mockResolvedValueOnce({ error: 'failed' });
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ await wait(CLAIMS_EVERY_MS * 2);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ await render('s2');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ error.mockRestore();
+ });
+
+ it("asks nothing before Quality's second phase", async () => {
+ await render('s1', false);
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).not.toHaveBeenCalled();
+ expect(blocks()).toBeNull();
+ expect(attr('data-reading')).toBe('false');
+ });
+
+ it('asks nothing while there are changes to save: their save asks', async () => {
+ await render('s1', true, true);
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).not.toHaveBeenCalled();
+ expect(attr('data-reading')).toBe('true');
+ await render('s2');
+ await wait(CLAIMS_DELAY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ expect(attr('data-reading')).toBe('false');
+ });
+
+ it('reads the block left for later once the person leaves it, with no save', async () => {
+ writing = 'Still writing this.';
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ expect(checkDraftClaims).toHaveBeenLastCalledWith('d1', 'Still writing this.');
+ writing = null;
+ act(() => recheck());
+ // Half a minute after the last ask, as any.
+ await wait(CLAIMS_EVERY_MS - 100);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ await wait(100);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ expect(checkDraftClaims).toHaveBeenLastCalledWith('d1', null);
+ // Nothing was left that time: leaving again asks nothing.
+ act(() => recheck());
+ await wait(CLAIMS_EVERY_MS * 2);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ });
+
+ it('asks again for blocks an ask had no calls left for, and stops once the day’s reads are made', async () => {
+ checkDraftClaims
+ .mockResolvedValueOnce({ blocks: [BLOCK], pending: 5, limited: false })
+ .mockResolvedValueOnce({ blocks: [BLOCK], pending: 2, limited: true });
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ expect(attr('data-reading')).toBe('true');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ expect(attr('data-limited')).toBe('true');
+ expect(attr('data-reading')).toBe('false');
+ await render('s2');
+ await wait(CLAIMS_EVERY_MS * 2);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ });
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts
new file mode 100644
index 000000000..0ebb9f261
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts
@@ -0,0 +1,133 @@
+'use client';
+
+import { useCallback, useEffect, useRef, useState } from 'react';
+import { checkDraftClaims } from '@/lib/actions/content-drafts';
+import type { ClaimBlock } from '@/lib/content/claims';
+
+/** How long after a save the claims are asked about, as the sources' kinds are. */
+export const CLAIMS_DELAY_MS = 3_000;
+/** Asks no closer together than this: a save every few seconds of typing asks once. */
+export const CLAIMS_EVERY_MS = 30_000;
+
+export interface ClaimsRead {
+ /** Each block's claims, null until the first read. */
+ blocks: ClaimBlock[] | null;
+ /** The workspace's AI budget is spent: no more asks this session. */
+ paused: boolean;
+ /** The draft's claim reads for the day are made: no more asks this session. */
+ limited: boolean;
+ /** Some of the page isn't read yet: an ask is out, or blocks wait for the next. */
+ reading: boolean;
+ /**
+ * The person has left the block the last ask left for later (the editor
+ * lost focus): it is read with the next ask, CLAIMS_EVERY_MS after the
+ * last one, with no save needed.
+ */
+ recheck: () => void;
+}
+
+/**
+ * The claims in the draft's own words (Quality CE-045). The API reads the
+ * draft as saved and keeps each block's read, so the editor asks a few
+ * seconds after a save, CLAIMS_EVERY_MS apart at most, one ask at a time,
+ * and not while there are changes to save (the API would read the page
+ * before them). It leaves the block the person is writing in (`writingIn`,
+ * read when it asks; null when they aren't), and asks again for one left,
+ * or for blocks an ask had no calls left for, without waiting for a save.
+ * A spent AI budget or the day's reads made stop the asks for the session;
+ * an API with them off stops them silently; a failed ask waits for the next
+ * save.
+ */
+export function useClaims(
+ draftId: string,
+ savedAt: string,
+ enabled: boolean,
+ unsaved: boolean,
+ writingIn: () => string | null,
+): ClaimsRead {
+ const [blocks, setBlocks] = useState<ClaimBlock[] | null>(null);
+ const [paused, setPaused] = useState(false);
+ const [limited, setLimited] = useState(false);
+ const [off, setOff] = useState(false);
+ const [out, setOut] = useState(false);
+ const [pending, setPending] = useState(0);
+ // Bumped when the next ask needn't wait for a save: one is out, or
+ // something was left for later.
+ const [again, setAgain] = useState(0);
+ const asking = useRef(false);
+ const latest = useRef(savedAt);
+ const askedFor = useRef<string | null>(null);
+ const lastAsk = useRef(0);
+ // What the last ask left: the block being written, or blocks past its calls.
+ const skipped = useRef<string | null>(null);
+ const left = useRef(false);
+ const reader = useRef(writingIn);
+ const open = useRef(true);
+ useEffect(() => {
+ reader.current = writingIn;
+ latest.current = savedAt;
+ });
+ useEffect(() => {
+ open.current = true;
+ return () => {
+ open.current = false;
+ };
+ }, []);
+
+ useEffect(() => {
+ // Changes not saved yet: their save asks.
+ if (!enabled || paused || limited || off || unsaved) return;
+ if (askedFor.current === savedAt && !left.current) return;
+ const wait = Math.max(CLAIMS_DELAY_MS, lastAsk.current + CLAIMS_EVERY_MS - Date.now());
+ const timer = setTimeout(() => {
+ // One at a time: a save while one is out is asked about after it.
+ if (asking.current) return;
+ const skip = reader.current();
+ asking.current = true;
+ askedFor.current = savedAt;
+ lastAsk.current = Date.now();
+ skipped.current = skip;
+ left.current = false;
+ setOut(true);
+ void checkDraftClaims(draftId, skip)
+ .then((result) => {
+ if (!open.current) return;
+ if ('error' in result) {
+ if (result.error === 'ai_budget') setPaused(true);
+ else if (result.error === 'off') setOff(true);
+ // Failed: asked about again after the next save, not on a timer.
+ else console.error('Failed to read the claims:', result.error);
+ setBlocks((prev) => prev ?? []);
+ setPending(0);
+ return;
+ }
+ setBlocks(result.blocks);
+ setPending(result.pending);
+ if (result.limited) setLimited(true);
+ else if (result.pending > 0) left.current = true;
+ })
+ .catch((err) => {
+ console.error('Failed to read the claims:', err);
+ if (open.current) setBlocks((prev) => prev ?? []);
+ })
+ .finally(() => {
+ asking.current = false;
+ if (!open.current) return;
+ setOut(false);
+ if (latest.current !== askedFor.current || left.current) setAgain((n) => n + 1);
+ });
+ }, wait);
+ return () => clearTimeout(timer);
+ }, [draftId, savedAt, enabled, paused, limited, off, unsaved, again]);
+
+ const recheck = useCallback(() => {
+ if (skipped.current === null) return;
+ skipped.current = null;
+ left.current = true;
+ // One out asks again when it's back.
+ if (!asking.current) setAgain((n) => n + 1);
+ }, []);
+
+ const reading = enabled && !paused && !limited && !off && (blocks === null || out || pending > 0);
+ return { blocks, paused, limited, reading, recheck };
+}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
index c937e5896..29d16f661 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
@@ -18,6 +18,7 @@ const saveContentDraft = vi.fn();
const setContentDraftPageType = vi.fn();
const setContentDraftAuthor = vi.fn();
const keepDraftSource = vi.fn();
+const checkDraftClaims = vi.fn();
const checkDraftLinks = vi.fn();
const getSiteTrust = vi.fn();
vi.mock('@/lib/actions/audits', () => ({
@@ -83,6 +84,7 @@ vi.mock('@/lib/actions/content-drafts', () => ({
setContentDraftPageType: (...args: unknown[]) => setContentDraftPageType(...args),
setContentDraftAuthor: (...args: unknown[]) => setContentDraftAuthor(...args),
keepDraftSource: (...args: unknown[]) => keepDraftSource(...args),
+ checkDraftClaims: (...args: unknown[]) => checkDraftClaims(...args),
checkDraftLinks: (...args: unknown[]) => checkDraftLinks(...args),
}));
vi.mock('next/navigation', () => ({ useParams: () => ({ draftId: 'd1' }) }));
@@ -280,6 +282,7 @@ beforeEach(() => {
setContentDraftPageType.mockReset().mockResolvedValue(undefined);
setContentDraftAuthor.mockReset().mockResolvedValue(undefined);
keepDraftSource.mockReset();
+ checkDraftClaims.mockReset().mockResolvedValue({ blocks: [], pending: 0, limited: false });
checkDraftLinks.mockReset().mockResolvedValue({ links: [], skipped: [] });
getSiteTrust.mockReset().mockRejectedValue(new Error('not in this test'));
getContentAuthors.mockReset().mockResolvedValue(null);
@@ -2639,6 +2642,185 @@ describe('the side panel', () => {
});
});
+ describe('Claims with no source (Quality CE-045)', () => {
+ afterEach(() => {
+ delete process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE;
+ vi.useRealTimers();
+ });
+ const said = 'Ledgerly is the fastest forecasting app.';
+ const claimed = draft({
+ bodyHtml: `<h1>Pipeline forecasting</h1><p>${said} It is easy to set up for any team.</p>`,
+ });
+ const redMarks = () => container.querySelectorAll('.ProseMirror .decoration-red-500');
+ // Trust reads the page once the brand's domains are read, with the sources.
+ beforeEach(() => {
+ getDraftSources.mockResolvedValue({
+ data: {
+ prompts: [],
+ fanouts: [],
+ citedPages: [],
+ gscQueries: [],
+ brandDomains: ['acme.com'],
+ competitorDomains: [],
+ },
+ choices: [],
+ });
+ });
+ const openQuality = async () => {
+ const chip = [...container.querySelectorAll<HTMLButtonElement>('header button')].find((b) =>
+ b.textContent?.startsWith('Quality'),
+ )!;
+ await act(async () => chip.click());
+ return [...panel()!.querySelectorAll('li')].find((li) =>
+ li.textContent?.includes('claim has no source'),
+ )!;
+ };
+
+ it('underlines a claim the model read, and Quality offers Add source and Remove', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ checkDraftClaims.mockResolvedValue({
+ blocks: [
+ {
+ text: `${said} It is easy to set up for any team.`,
+ claims: [{ text: 'the fastest forecasting app', kind: 'superlative' }],
+ },
+ ],
+ pending: 0,
+ limited: false,
+ });
+ getContentDraft.mockResolvedValue(claimed);
+ window.innerWidth = 1440;
+ await renderPage();
+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));
+ // Not writing in the page: no block left for later.
+ expect(checkDraftClaims).toHaveBeenCalledWith('d1', null);
+ expect(redMarks()).toHaveLength(1);
+ expect(redMarks()[0].textContent).toBe('the fastest forecasting app');
+ expect(redMarks()[0].getAttribute('title')).toContain('No source for this claim');
+
+ const row = await openQuality();
+ expect(row.textContent).toContain('1 claim has no source');
+ expect(row.textContent).toContain('AI check');
+ // Add source: the claim selected, the link dialog open on it; Apply links those words.
+ const add = [...row.querySelectorAll('button')].find((b) => b.textContent === 'Add source')!;
+ expect(add.getAttribute('aria-label')).toBe('Add a source to “the fastest forecasting app”');
+ await act(async () => add.click());
+ const field = document.querySelector<HTMLInputElement>('#content-link-href')!;
+ expect(field).not.toBeNull();
+ const { state } = (
+ container.querySelector('.ProseMirror') as HTMLElement & { editor: Editor }
+ ).editor;
+ expect(state.doc.textBetween(state.selection.from, state.selection.to)).toBe(
+ 'the fastest forecasting app',
+ );
+ await act(async () => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(
+ field,
+ 'https://g2.example/forecasting',
+ );
+ field.dispatchEvent(new Event('input', { bubbles: true }));
+ });
+ const apply = [...document.querySelectorAll('button')].find(
+ (b) => b.textContent === 'Apply',
+ )!;
+ await act(async () => apply.click());
+ const link = container.querySelector<HTMLAnchorElement>(
+ '.ProseMirror a[href="https://g2.example/forecasting"]',
+ );
+ expect(link?.textContent).toBe('the fastest forecasting app');
+ });
+
+ it('takes the claim’s sentence out on Remove', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ checkDraftClaims.mockResolvedValue({
+ blocks: [
+ {
+ text: `${said} It is easy to set up for any team.`,
+ claims: [{ text: 'the fastest forecasting app', kind: 'superlative' }],
+ },
+ ],
+ pending: 0,
+ limited: false,
+ });
+ getContentDraft.mockResolvedValue(claimed);
+ window.innerWidth = 1440;
+ await renderPage();
+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));
+ const row = await openQuality();
+ const remove = [...row.querySelectorAll('button')].find((b) => b.textContent === 'Remove')!;
+ await act(async () => remove.click());
+ const page = container.querySelector('.ProseMirror')!.textContent!;
+ expect(page).not.toContain(said);
+ expect(page).toContain('It is easy to set up for any team.');
+ });
+
+ it('takes a list item Remove empties out with its sentence', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ checkDraftClaims.mockResolvedValue({
+ blocks: [
+ { text: said, claims: [{ text: 'the fastest forecasting app', kind: 'superlative' }] },
+ ],
+ pending: 0,
+ limited: false,
+ });
+ getContentDraft.mockResolvedValue(
+ draft({
+ bodyHtml:
+ `<h1>Pipeline forecasting</h1><ul><li><p>${said}</p></li><li><p>Easy to set up.</p></li></ul>` +
+ '<p>Try it free.</p>',
+ }),
+ );
+ window.innerWidth = 1440;
+ await renderPage();
+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));
+ const row = await openQuality();
+ const remove = [...row.querySelectorAll('button')].find((b) => b.textContent === 'Remove')!;
+ await act(async () => remove.click());
+ const items = [...container.querySelectorAll('.ProseMirror li')].map((li) => li.textContent);
+ expect(items).toEqual(['Easy to set up.']);
+ });
+
+ // A figure the rules read, with no source.
+ const figured = draft({
+ bodyHtml: '<h1>Pipeline forecasting</h1><p>Teams cut 40% of their busywork with it.</p>',
+ });
+
+ it('underlines a figure with no source with phase 2, the model having read no claim', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ getContentDraft.mockResolvedValue(figured);
+ window.innerWidth = 1440;
+ await renderPage();
+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));
+ expect(redMarks()).toHaveLength(1);
+ expect(redMarks()[0].textContent).toBe('Teams cut 40% of their busywork with it.');
+ });
+
+ it("asks nothing, underlines nothing and offers no Add source before Quality's second phase", async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '1';
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ getContentDraft.mockResolvedValue(figured);
+ window.innerWidth = 1440;
+ await renderPage();
+ await act(async () => void (await vi.advanceTimersByTimeAsync(40_000)));
+ expect(checkDraftClaims).not.toHaveBeenCalled();
+ expect(redMarks()).toHaveLength(0);
+ const chip = [...container.querySelectorAll<HTMLButtonElement>('header button')].find((b) =>
+ b.textContent?.startsWith('Quality'),
+ )!;
+ await act(async () => chip.click());
+ const row = [...panel()!.querySelectorAll('li')].find((li) =>
+ li.textContent?.includes('figure has no source'),
+ )!;
+ expect(row).toBeDefined();
+ const labels = [...row.querySelectorAll('button')].map((b) => b.textContent);
+ expect(labels).toEqual(['Show']);
+ });
+ });
+
describe('Sources by kind (Quality CE-046)', () => {
afterEach(() => {
delete process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE;
diff --git a/web/src/lib/actions/content-drafts.ts b/web/src/lib/actions/content-drafts.ts
index d130fb220..799d9a830 100644
--- a/web/src/lib/actions/content-drafts.ts
+++ b/web/src/lib/actions/content-drafts.ts
@@ -38,6 +38,7 @@ import { detectPageType, siteTypeOf, type SiteType } from '@/lib/content/page-ty
import { sanitizeDraftHtml } from '@/lib/content/sanitize-draft-html';
import { matchPagePrompts } from '@/lib/content/page-prompts';
import type { LinkCheck } from '@/lib/content/quality-checks';
+import { CLAIM_KINDS, type ClaimBlock } from '@/lib/content/claims';
import { MAX_SOURCE_SITES, type AiSourceClass } from '@/lib/content/source-class';
import {
NO_DRAFT_RULES,
@@ -732,6 +733,69 @@ export async function classifyDraftSources(
}
}
+/**
+ * Quality's claims in the draft's own words (CE-045): the API reads the
+ * draft as saved, each block the model hasn't read yet, and leaves the one
+ * the person is writing in (`writingIn`, its text as Trust reads it; null
+ * when they aren't). Returned, not thrown: 'ai_budget'
+ * when the workspace's AI budget is spent; 'off' before Quality's phase 2
+ * is live on the API.
+ */
+export async function checkDraftClaims(
+ id: string,
+ writingIn: string | null,
+): Promise<
+ | { blocks: ClaimBlock[]; pending: number; limited: boolean }
+ | { error: 'invalid' | 'failed' | 'ai_budget' | 'off' }
+> {
+ if (!draftId.safeParse(id).success) return { error: 'invalid' };
+ const supabase = await createClient();
+ const {
+ data: { session },
+ } = await supabase.auth.getSession();
+ if (!session) return { error: 'failed' };
+ try {
+ const res = await fetch(`${API_BASE_URL}/api/content-pages/claims`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${session.access_token}`,
+ },
+ // A block too long to send as one is read all the same.
+ body: JSON.stringify({
+ draftId: id,
+ skip: (typeof writingIn === 'string' ? writingIn.slice(0, 20000) : '') || undefined,
+ }),
+ });
+ if (res.status === 429) {
+ const body = (await res.json().catch(() => ({}))) as { code?: string };
+ return { error: body.code === 'ai_budget' ? 'ai_budget' : 'failed' };
+ }
+ if (res.status === 404) {
+ const body = (await res.json().catch(() => ({}))) as { code?: string };
+ return { error: body.code === 'off' ? 'off' : 'failed' };
+ }
+ if (!res.ok) return { error: 'failed' };
+ const body = (await res.json()) as {
+ paragraphs?: ClaimBlock[];
+ pending?: number;
+ limited?: boolean;
+ };
+ const kinds: readonly string[] = CLAIM_KINDS;
+ return {
+ blocks: (body.paragraphs ?? []).map((block) => ({
+ text: block.text,
+ claims: block.claims.filter((claim) => kinds.includes(claim.kind)),
+ })),
+ pending: body.pending ?? 0,
+ limited: body.limited ?? false,
+ };
+ } catch (err) {
+ console.error('Failed to read the draft claims:', err);
+ return { error: 'failed' };
+ }
+}
+
/**
* "Team" in Start (CE-015): the draft sent to the Action Center as an action
* for someone on the team to write (the API's from-content-draft.js), or the
diff --git a/web/src/lib/content/claims.ts b/web/src/lib/content/claims.ts
new file mode 100644
index 000000000..72c07a69b
--- /dev/null
+++ b/web/src/lib/content/claims.ts
@@ -0,0 +1,21 @@
+/**
+ * The claims in a draft's own words (Quality spec §3, CE-045), as the API
+ * reads them (content-quality-claims.js): what a reader would want a source
+ * for, each in its block's words. Trust counts them with the figures it
+ * reads by rule; the editor underlines one with no source in its block.
+ */
+
+export const CLAIM_KINDS = ['number', 'stat', 'superlative', 'fact'] as const;
+export type ClaimKind = (typeof CLAIM_KINDS)[number];
+
+export interface DraftClaim {
+ /** The claim's words, as its block has them. */
+ text: string;
+ kind: ClaimKind;
+}
+
+/** A block of the page with its claims: its words as Trust's blocks have them (trustBlocks). */
+export interface ClaimBlock {
+ text: string;
+ claims: DraftClaim[];
+}
diff --git a/web/src/lib/content/quality-checks.test.ts b/web/src/lib/content/quality-checks.test.ts
index 13260590d..a02c24af8 100644
--- a/web/src/lib/content/quality-checks.test.ts
+++ b/web/src/lib/content/quality-checks.test.ts
@@ -406,3 +406,141 @@ describe('trust (Phase 2: what kind of source each link is, CE-046)', () => {
expect(before.weak).toEqual([]);
});
});
+
+describe('trust: the claims the model read (Phase 2, CE-045)', () => {
+ const NOW = Date.parse('2026-10-23T12:00:00Z');
+ const html =
+ '<p>Ledgerly is the fastest forecasting app. Every plan is SOC 2 certified.</p>' +
+ '<p>It is rated #1 by analysts (<a href="https://analysts.example/report">report</a>).</p>';
+ const read = (claims: Parameters<typeof trust>[0]['claims']) =>
+ trust({ blocks: trustBlocks(html), links: new Map(), brandDomains: [], claims, now: NOW });
+
+ it('counts a claim with no source in its block as a figure with none, and one with a source as sourced', () => {
+ const result = read([
+ {
+ text: 'Ledgerly is the fastest forecasting app. Every plan is SOC 2 certified.',
+ claims: [
+ { text: 'the fastest forecasting app', kind: 'superlative' },
+ { text: 'SOC 2 certified', kind: 'fact' },
+ ],
+ },
+ {
+ // As Trust reads the block: a space at the link's edge.
+ text: 'It is rated #1 by analysts ( report).',
+ claims: [{ text: 'rated #1 by analysts', kind: 'superlative' }],
+ },
+ ]);
+ expect(result.unsourced).toEqual([
+ 'Ledgerly is the fastest forecasting app.',
+ 'Every plan is SOC 2 certified.',
+ ]);
+ const block = 'Ledgerly is the fastest forecasting app. Every plan is SOC 2 certified.';
+ expect(result.marks).toEqual([
+ {
+ text: 'the fastest forecasting app',
+ sentence: 'Ledgerly is the fastest forecasting app.',
+ block,
+ },
+ { text: 'SOC 2 certified', sentence: 'Every plan is SOC 2 certified.', block },
+ ]);
+ expect(result.aiClaims).toBe(2);
+ expect(result.figures).toBe(3);
+ // 1 of 3 sourced: Trust is scored from the claims alone.
+ expect(result.checks.find((c) => c.id === 'claimsSourced')?.points).toBe(10);
+ expect(result.score).not.toBeNull();
+ });
+
+ it('finds a claim by its words when its block reads otherwise, and leaves Phase 1 as it was', () => {
+ const result = read([
+ { text: 'a block written since', claims: [{ text: 'SOC 2 certified', kind: 'fact' }] },
+ ]);
+ expect(result.unsourced).toEqual(['Every plan is SOC 2 certified.']);
+ const before = read(null);
+ expect(before.unsourced).toEqual([]);
+ expect(before.marks).toEqual([]);
+ expect(before.aiClaims).toBe(0);
+ expect(before.score).toBeNull();
+ });
+
+ it('says a figure the rules found is no AI check', () => {
+ const result = trust({
+ blocks: trustBlocks('<p>Teams cut 40% of their busywork. Ledgerly is the fastest app.</p>'),
+ links: new Map(),
+ brandDomains: [],
+ claims: [
+ {
+ text: 'Teams cut 40% of their busywork. Ledgerly is the fastest app.',
+ claims: [
+ { text: 'cut 40% of their busywork', kind: 'number' },
+ { text: 'the fastest app', kind: 'superlative' },
+ ],
+ },
+ ],
+ now: NOW,
+ });
+ expect(result.unsourced).toHaveLength(2);
+ expect(result.aiClaims).toBe(1);
+ // Underlined in the model's words where it read some, the figure's sentence too.
+ expect(result.marks.map((m) => m.text)).toEqual([
+ 'cut 40% of their busywork',
+ 'the fastest app',
+ ]);
+ });
+
+ it('leaves out a claim taken out of its block since, not one it makes up', () => {
+ // The claims were read with "SOC 2 certified." in the block; it's gone now.
+ const page = '<p>Ledgerly is the fastest forecasting app.</p>';
+ const result = trust({
+ blocks: trustBlocks(page),
+ links: new Map(),
+ brandDomains: [],
+ claims: [
+ {
+ text: 'Ledgerly is the fastest forecasting app.',
+ claims: [
+ { text: 'the fastest forecasting app', kind: 'superlative' },
+ { text: 'SOC 2 certified', kind: 'fact' },
+ ],
+ },
+ ],
+ now: NOW,
+ });
+ expect(result.unsourced).toEqual(['Ledgerly is the fastest forecasting app.']);
+ expect(result.marks.map((m) => m.text)).toEqual(['the fastest forecasting app']);
+ expect(result.figures).toBe(1);
+ });
+
+ it("finds each claim in its own block, and lists them in the page's order", () => {
+ // The first block's claim moved to another block since it was read;
+ // the model's claims come after the rules' figures in the read.
+ const page =
+ '<p>Teams cut 40% of their busywork.</p>' +
+ '<p>Ledgerly is the fastest app. Every plan is SOC 2 certified.</p>';
+ const result = trust({
+ blocks: trustBlocks(page),
+ links: new Map(),
+ brandDomains: [],
+ claims: [
+ {
+ text: 'Ledgerly is the fastest app.',
+ claims: [
+ { text: 'the fastest app', kind: 'superlative' },
+ { text: 'SOC 2 certified', kind: 'fact' },
+ ],
+ },
+ { text: 'Teams cut 40% of their busywork.', claims: [] },
+ ],
+ now: NOW,
+ });
+ expect(result.unsourced).toEqual([
+ 'Teams cut 40% of their busywork.',
+ 'Ledgerly is the fastest app.',
+ 'Every plan is SOC 2 certified.',
+ ]);
+ expect(result.marks.map((m) => [m.text, m.block])).toEqual([
+ ['Teams cut 40% of their busywork.', 'Teams cut 40% of their busywork.'],
+ ['the fastest app', 'Ledgerly is the fastest app. Every plan is SOC 2 certified.'],
+ ['SOC 2 certified', 'Ledgerly is the fastest app. Every plan is SOC 2 certified.'],
+ ]);
+ });
+});
diff --git a/web/src/lib/content/quality-checks.ts b/web/src/lib/content/quality-checks.ts
index 22377fab1..8f2f35b35 100644
--- a/web/src/lib/content/quality-checks.ts
+++ b/web/src/lib/content/quality-checks.ts
@@ -2,6 +2,7 @@ import { classifyDomain, normalizeDomain } from '@/lib/citations/classify';
import type { ContentAuthor } from './authors';
import { cleanHref } from './html-allowlist';
import { ownText, sentencesOf } from './readability';
+import type { ClaimBlock } from './claims';
import { askableSite, sourceClass, type AiSourceClass, type SourceClass } from './source-class';
/**
@@ -263,9 +264,20 @@ export interface TrustRead extends Score<TrustCheckId> {
/** Sources older than FRESH_MONTHS, and how many give a date at all. */
stale: { url: string; text: string }[];
dated: number;
- /** Sentences with a figure and no source in their block, and how many have a figure. */
+ /**
+ * Sentences with a figure or a claim and no source in their block, and
+ * how many have one.
+ */
unsourced: string[];
figures: number;
+ /**
+ * Phase 2 (CE-045): what the draft underlines, in the page's order: the
+ * model's claims with no source in their own words, the other figures in
+ * their sentences; and how many unsourced sentences only the model found
+ * ("AI check").
+ */
+ marks: ClaimMark[];
+ aiClaims: number;
/**
* Phase 2 (CE-046): weak or competitors' sources the person hasn't kept,
* the page's first first (`ai` when the model read its site), and how
@@ -275,6 +287,17 @@ export interface TrustRead extends Score<TrustCheckId> {
classified: number;
}
+/**
+ * A claim with no source, as the draft underlines it (CE-045): its words
+ * (the whole sentence for a figure read by rule), the sentence Remove takes
+ * out, and its block's text, the only place its words are looked for.
+ */
+export interface ClaimMark {
+ text: string;
+ sentence: string;
+ block: string;
+}
+
/** What Trust needs to tell a link's kind (Phase 2, CE-046). */
export interface SourceRead {
competitorDomains: string[];
@@ -301,6 +324,9 @@ export interface SourceRead {
* social posts) or a competitor's, unless the person kept it. A source the
* rules can't place is left out of both; two placed sources score Trust on
* their own.
+ *
+ * With `claims` (Phase 2, CE-045), the claims the model read count as the
+ * figures do, each sentence once: Trust is scored from them alone too.
*/
export function trust({
blocks,
@@ -309,6 +335,7 @@ export function trust({
siteTrust = null,
quote = null,
sources: kinds = null,
+ claims = null,
now,
}: {
/** The page's blocks (trustBlocks). */
@@ -325,21 +352,64 @@ export function trust({
quote?: boolean | null;
/** Phase 2: what each source is (CE-046); left out before. */
sources?: SourceRead | null;
+ /** Phase 2: the claims the model read in the page's own words (CE-045); left out before. */
+ claims?: readonly ClaimBlock[] | null;
now: number;
}): TrustRead {
const all = pageLinks(blocks, brandDomains);
const checks: ScoreCheck<TrustCheckId>[] = [];
- // Each sentence once: a nested list item's text is its parent's too.
- const figures = new Map<string, boolean>();
+ // Each sentence once, where the page has it first: a nested list item's
+ // text is its parent's too.
+ const figures = new Map<string, { sourced: boolean; block: number }>();
+ const sourcedBlock = (index: number) => all.some((l) => l.external && l.block === index);
+ const addFigure = (sentence: string, block: number) => {
+ const had = figures.get(sentence);
+ figures.set(sentence, {
+ sourced: (had?.sourced ?? false) || sourcedBlock(block),
+ block: had?.block ?? block,
+ });
+ };
blocks.forEach((b, index) => {
- const sourced = all.some((l) => l.external && l.block === index);
- for (const sentence of sentencesOf(b.text)) {
- if (hasFigure(sentence)) figures.set(sentence, (figures.get(sentence) ?? false) || sourced);
- }
+ for (const sentence of sentencesOf(b.text)) if (hasFigure(sentence)) addFigure(sentence, index);
});
- const figureSentences = [...figures].map(([sentence, sourced]) => ({ sentence, sourced }));
+ // The model's claims (CE-045): each in its block, found by the block's
+ // words, else by its own; its sentence counts as a figure's does. A claim
+ // no block has any more (written over since it was read) is left out.
+ const byRule = new Set(figures.keys());
+ const claimed: { text: string; sentence: string; block: number }[] = [];
+ for (const block of claims ?? []) {
+ const own = blocks.findIndex((b) => b.text === block.text);
+ for (const claim of block.claims) {
+ const index =
+ own !== -1 && blocks[own].text.includes(claim.text)
+ ? own
+ : blocks.findIndex((b) => b.text.includes(claim.text));
+ if (index === -1) continue;
+ const sentence =
+ sentencesOf(blocks[index].text).find((s) => s.includes(claim.text)) ?? claim.text;
+ addFigure(sentence, index);
+ claimed.push({ text: claim.text, sentence, block: index });
+ }
+ }
+ // In the page's order: Show, Add source and Remove act on the first.
+ const figureSentences = [...figures]
+ .map(([sentence, f]) => ({ sentence, ...f }))
+ .sort((a, b) => a.block - b.block);
const unsourced = figureSentences.filter((f) => !f.sourced).map((f) => f.sentence);
+ const unsourcedSet = new Set(unsourced);
+ const claimedUnsourced = claimed.filter((c) => unsourcedSet.has(c.sentence));
+ const claimSentences = new Set(claimedUnsourced.map((c) => c.sentence));
+ const marks = [
+ ...claimedUnsourced,
+ ...figureSentences
+ .filter((f) => !f.sourced && !claimSentences.has(f.sentence))
+ .map((f) => ({ text: f.sentence, sentence: f.sentence, block: f.block })),
+ ]
+ .sort((a, b) => a.block - b.block)
+ .filter((m, i, list) => list.findIndex((o) => o.text === m.text && o.block === m.block) === i)
+ .map(({ text, sentence, block }) => ({ text, sentence, block: blocks[block].text }));
+ const aiClaims = unsourced.filter((sentence) => !byRule.has(sentence)).length;
if (figureSentences.length) {
checks.push({
id: 'claimsSourced',
@@ -440,6 +510,8 @@ export function trust({
dated: sources.length,
unsourced,
figures: figureSentences.length,
+ marks,
+ aiClaims,
weak,
classified: classified.length,
};