Skip to content

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

Merged
gkhngyk merged 19 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-claims-editor
Oct 24, 2026
Merged

gkhngyk merged 19 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-claims-editor

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Quality Phase 2, CE-045 "Claim detection in user text", part b: the editor. Stacked on #1457 (part a, the server's POST /claims), which sits on #1451; review those first. Everything sits behind NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2. At phase 0/1 nothing is asked, nothing is underlined, there is no Add source / Remove, and trust() comes out as before.

When the editor asks (useClaims)

  • A few seconds after a save (3 s), at most every 30 s, one ask at a time, and never while there are changes to save. The API reads the draft as saved, so the editor waits for the save.
  • It leaves the block the cursor is in (skip). That block's text is built the way Trust and the API read it (writingBlock: the cursor's paragraph, list item, quote or cell serialised and read with trustBlocks), so the server's hash matches.
  • Once the person leaves the editor (blur, e.g. to open Quality or Before you publish), the block left for later is read with the next ask, no save needed.
  • Blocks an ask had no calls left for (pending) are asked about again 30 s later. Once the draft's day of reads is used up (limited), asks stop for the session and Quality says so. A spent AI budget pauses them (as feat(content): read the kind of a source's site the rules can't place with AI (CE-046, part b) #1451's source reads do), and an API with them off stops them silently. A failed ask waits for the next save.

Trust (trust({ claims }))

  • Each claim is looked up in its own block, else by its words; a claim no block has any more (written over since it was read) is left out.
  • Its sentence counts as a figure's does, each sentence once, in the page's order. Trust is scored from the claims alone too: at phase 2, one AI-found superlative on a page with no figures and no dated sources gives a Trust score (0 if unsourced) where there was none before. The chip can move about 3 s after opening, when the first answer lands.
  • TrustRead.marks: what the draft underlines, each with its block's text. aiClaims: unsourced sentences only the model found, so the Quality line says "claims" with the AI check tag.

In the page

  • A red wavy underline (decoration only, with a dark: colour) on each unsourced claim's words, and on the sentences of figures read by rule. It is looked for only inside that claim's block, never in a heading, ignoring the spacing differences between Trust's text and the page (( report), 40 %, line breaks).
  • On hover: "No source for this claim. Add a source, or take it out." The spec puts the buttons on the hover; as with the weak sources (feat(content): read the kind of a source's site the rules can't place with AI (CE-046, part b) #1451), they are on Quality's suggestion instead.
  • Add source selects the claim's words and opens the toolbar's link dialog on them; Apply links those words.
  • Remove takes the claim's sentence out, with the space after it. A list item (or list) left empty goes too. Undo brings it back.
  • Both act on the first unsourced claim in the page's order.
  • Before you publish says "Still reading the claims in your own words, so Trust may change" while an ask is out or blocks wait.

Related issue

Quality spec (Drive), Phase 2, CE-045 (part b). Stacked on #1457.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. With feat(content): read the claims in a draft's own paragraphs with AI, kept by the paragraph (CE-045, part a) #1457's 00266 applied, set CONTENT_QUALITY_PHASE=2 (server) and NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2 (web).
  2. Open a draft and write "Ledgerly is the fastest forecasting app. Every plan is SOC 2 certified." in one paragraph, then click outside the editor.
  3. About 3 s after the save, "the fastest forecasting app" and "SOC 2 certified" get a red wavy underline. Quality › Trust says "2 claims have no source" with the AI check tag.
  4. Click Add source: the claim's words are selected and the link dialog opens. Paste a URL and Apply; those words become the link. The underline goes on the next read.
  5. Click Remove on a claim in a list item: the sentence and the empty item go. Ctrl+Z brings them back.
  6. With the phase at 1: no underline, and no Add source / Remove.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Web: yarn format, yarn lint, yarn typecheck, yarn test (3,522 tests) and yarn build pass.

A pre-push review's points are in:

  • a claim whose sentence is gone no longer comes back as a made-up one;
  • skip is the block as saved, not asked while unsaved;
  • the block left for later is read on blur;
  • pending is asked again, and limited shows a note;
  • marks only in the claim's own block, never in headings, matched ignoring spacing;
  • page order for Show / Add source / Remove;
  • the empty list item goes on Remove;
  • aria-labels on Add source / Remove;
  • a runtime check on the server action's writingIn.

The browser check (light/dark, 1024 px, focus in the link dialog after Add source) is owed and batched with #1446–#1457.

🤖 Generated with Claude Code

cihan-gyk and others added 9 commits October 24, 2026 13:18
…he weak ones (CE-046, part a)

Quality phase 2 (NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2), by rules only:

- sourceClass(): primary (official, research, standards), secondary (news,
  reviews, Wikipedia), weak (forums, social posts, uploaded papers), a
  competitor's page (primary on a comparison) or the brand's own; an
  address the rules can't place is left out (an AI read comes in part b)
- Trust's primarySources (15) and noWeakSources (10); two placed sources
  score Trust on their own
- Quality suggests replacing weak sources (Show, Keep) and adding a
  primary one, once Trust is scored; the editor underlines weak sources
  in amber (a decoration: never exported)
- 00263: content_drafts.kept_sources (≤ 50) and content_draft_keep_source()
- byUrl keeps a link's first place, so Show goes there

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… with AI (CE-046, part b)

Quality phase 2 (web NEXT_PUBLIC_CONTENT_QUALITY_PHASE and server
CONTENT_QUALITY_PHASE at 2):

- POST /api/content-pages/source-classes reads the sites a draft links
  (as saved) that the editor's rules can't place: the model sees each
  site's address alone and answers primary, secondary or weak; each read
  is kept for every workspace 90 days (00264 content_source_classes); 20
  sites a read, 30 reads a draft a day, its own rate limit
- the reads draw on the AI budget as their own feature, "quality" (00264
  widens prompt_improve_usage.feature): a small hold (holdUsd), left out
  of the median that sizes other calls' holds and the Improve tab's
  estimate; a read cut off by its timeout keeps its hold; Billing lists it
- the editor asks 3 s after a save (useSourceClasses), Trust takes the
  reads for sites the rules can't place, the weak-sources suggestion is
  tagged "AI check", and a spent budget pauses the reads with a note

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rce-classes-ai

# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx
#	web/src/lib/actions/content-drafts.test.ts
#	web/src/lib/content/quality-checks.test.ts
#	web/src/lib/content/quality-checks.ts
#	web/src/lib/content/source-class.ts
#	web/src/types/supabase.ts
…a day, and skip kept sources (CE-046, part b review)

- SITE_NAME (LDH, a dot, a letter TLD; no IP, no single label) in
  keptSite/linkedSites, the editor's unplacedSites and 00264's check; a
  label that reads as words isn't asked about either
- the model may answer unknown, which Trust leaves out; it, and a site
  the model left out, is kept a day, so it isn't asked again (and
  charged) after every save
- a site whose every link the person kept isn't asked about (route and
  editor); a kept link counts in Trust with or without a read
- a failed classifyDraftSources call lets its sites go (.catch/.finally)
- .env.example: phase 2 turns the AI source reads on, from the AI budget

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rce-classes-ai

# Conflicts:
#	supabase/schema.sql
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
…ept by the paragraph (CE-045, part a)

Quality phase 2 (CONTENT_QUALITY_PHASE at 2), server side:

- POST /api/content-pages/claims reads the draft as saved: each paragraph
  and list item long enough to hold a claim; the model finds what a reader
  would want a source for (number, stat, superlative, fact), each claim in
  the paragraph's own words or dropped, five a paragraph at most
- 00266 content_quality_claims keeps the reads by draft and paragraph
  hash: an unchanged paragraph isn't read again, a removed one's row goes;
  the paragraph being written (skip) waits; 12 paragraphs a call, 2 calls
  an ask, one after the other
- the calls draw on the AI budget as "quality" (holdUsd 0.004), and share
  one day's cap per draft with the source kinds' reads
  (content-quality-calls.js, QUALITY_CALLS_PER_DAY 60)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s too, and keep a missed answer as read (CE-045, part a review)

- draftParagraphs reads p, li, blockquote, td and th as trustBlocks does,
  with ownText's spacing (a line break, sibling paragraphs): the answer is
  { paragraphs: [{ text, claims }] }, so the editor knows each claim's block
- blocks from 12 characters ("Award-winning support"); a call takes 12
  paragraphs or 6,000 characters, whichever comes first
- an answer billed that missed the schema is charged and its paragraphs
  read with none (not sent, and charged, on every save); a kind the editor
  doesn't know drops that claim only; a paragraph answered twice keeps both
- claims leave 10 of the day's Quality calls to the sources' kinds, and the
  route has its own limiter; the reading's version is in the hash; logs
  carry no page words

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…underline the unsourced ones (CE-045, part b)

The editor asks the API for the claims a few seconds after a save (never
with changes to save), leaving the block being written until the person
leaves it. Trust counts each claim in its own block as a figure, the
draft underlines the unsourced ones in their blocks, and Quality's
suggestion gets Add source (link dialog on the claim's words) and Remove.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 24, 2026
cihan-gyk and others added 9 commits October 24, 2026 17:01
… per site (CE-046, part b review)

One generateObject per site the rules can't place, run together with
Promise.allSettled: no site's name reaches another's read, and a failed
site keeps the others' reads. Each read holds $0.0005; the day's cap
counts sites (SOURCE_READS_PER_DAY = 40). An answer off the schema is
charged and kept as unknown for a day. The route logs an error's name
and message only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-claims

# Conflicts:
#	server/src/lib/content-source-class.js
…tch claims across curly quotes, log no page words (CE-045, part a review)

- 00266 gets a `missed` column: an answer that missed the schema (cut
  short, or blocked by the provider's filter) keeps its paragraphs as read
  with no claims, and they're read again after MISSED_DAYS (1).
- keptClaims compares folded copies (’ ‘ → ', “ ” → ", ‐ ‑ – — → -),
  one character for one, and keeps the paragraph's own span.
- The claims route logs an error's name and message only: a provider's
  error carries the request, the page's paragraphs.
- QUALITY_CALLS_PER_DAY = 90, the claims leaving the sources'
  SOURCE_READS_PER_DAY (40) now that each site is a call: the claims keep
  their 50 calls a day.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d log no whole error (CE-046, part b review)

When no site is read, the error thrown is a spent budget's if any (429,
the editor pauses) rather than the first site's. An ask reads its sites
five at a time, so 20 holds and their queries don't go out at once. A
site's hold is $0.001 (the model's thinking is billed as output). The
route's error log keeps the stack, not the provider's request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-claims

# Conflicts:
#	server/src/lib/content-source-class.js
…er the new ones, and fold more quote and dash forms (CE-045, part a review)

A paragraph whose answer missed the schema is read again after a day in
a call of its own, after the paragraphs not read yet: one the provider's
filter blocks no longer keeps its neighbours unread every day. The fold
also covers low quotes, primes, figure and horizontal-bar dashes and the
minus sign. The claims route keeps the error's stack in its log. Tests
pin the select's columns, both fold directions and the route's log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Checked on top of #1457: useClaims (one ask at a time, none while unsaved, skip read at ask time, blur recheck, pending retried 30 s apart and bounded by the server's daily cap, limited/paused/off stop it), Trust's claim lookup and page-order marks, textRanges (block-scoped, no headings or code, whitespace-insensitive), Remove's empty list item / list / quote cleanup (a table cell keeps its paragraph), the toolbar's one-shot linkRequest, and the i18n keys (all resolve in en.json). At phase 1, claims stays null, so trust() and the editor behave as before. Both merge commits carry no changes of their own.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 24, 2026
@gkhngyk
gkhngyk merged commit d2a7343 into ansvisor:main Oct 24, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants