Repository navigation
feat(content): read the claims in a draft's own paragraphs with AI, kept by the paragraph (CE-045, part a) - #1457
Conversation
…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
…fter ansvisor#1435 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. Three small follow-ups:
-
An answer that misses the schema marks its paragraphs as read until their words change (low).
server/src/lib/content-quality-claims.js:169-172keeps each paragraph of that call (up to 12) with no claims, and they aren't read again.- A schema miss also covers an answer cut short or blocked by the provider's safety filter. Claim-heavy pages (health, finance) are the likeliest to hit that filter.
- Fix: mark those rows (e.g. a
missedcolumn in 00266, which isn't on prod yet) and read them again after a day, as #1451 does for anunknownsite.
-
A claim has to match the paragraph character for character (low).
keptClaims(:135) drops a claim the model copies with a straight apostrophe or quote where the page has a curly one (world’s fastest), or with another dash.- Fix: compare folded copies of both (’ ‘ → ', “ ” → ", – — → -). Each is a one-for-one character swap, so positions line up, and you can keep the paragraph's own span.
- A test with a curly apostrophe would pin it.
-
The route's error log can carry the paragraphs (low).
server/src/routes/content-pages.js:237logs the wholeerr.- A provider error from the first call (
APICallError, or aRetryErrorwrapping them) hasrequestBodyValues, which is the prompt with the page's words. pino's error serializer writes it out. - Fix: log
{ err: { name, message } }here, as the module does, so "Logs carry no page words" holds. - The other AI routes log the same way. A scrub in the logger's
errserializer would cover them all.
What I checked and found fine:
- 00266:
- RLS is on, with no policy and no anon or authenticated grants.
- Drafts cascade to it, and the primary key serves both the read and the prune.
- It leaves the AI-usage
featurecheck as 00264 sets it.
- Prod dry run, 00264 then 00266:
- Both apply cleanly.
- A member can't read either new table, and can't write to the claims table.
- The host, kind, hash and claims checks refuse bad values.
reserve_ai_usagetakesquality.- Deleting a draft removes its claims.
- The route:
- It's off below phase 2.
- It checks the draft's brand before reading.
- It has its own per-user limiter.
- Cost:
- Each call is held ($0.004) and charged on the workspace's AI budget as
quality. - A timeout keeps its hold, and a later call's failure keeps the reads before it.
- Limits: 50 claim calls a draft a day (10 left to sources), 2 calls an ask, and 12 paragraphs or 6,000 characters a call.
- Each call is held ($0.004) and charged on the workspace's AI budget as
- Prompt injection:
- The model sees only the numbered paragraphs.
- Its answer can only set that draft's rows, with words already in the paragraph and one of the four kinds.
- Nothing reaches another draft or workspace.
- Odd answers: an unknown
nor kind is dropped, and a paragraph answered twice is merged. - Blocks: the server reads the same blocks as the editor's
trustBlocks, with the same spacing.
00266 dry-runs cleanly on prod after 00264. Apply 00264 first, then 00266, before the server runs with CONTENT_QUALITY_PHASE=2.
… 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]>
|
Thanks. All three are in (710db97 + f5c90ea). #1451's per-site calls are merged in (883ee03, a137aef).
Cap, in step with #1451:
Server: |
# Conflicts: # supabase/schema.sql
gkhngyk
left a comment
There was a problem hiding this comment.
All three items done. The three merges (two of #1451, one of main) change nothing beyond their conflict resolutions.
- Missed answers:
- 00266 has
missed. - A missed paragraph is read again after
MISSED_DAYS, in a call of its own, after the new paragraphs (server/src/lib/content-quality-claims.js:286-308,batchesOfat:222-243).
- 00266 has
- Folded matching:
foldswaps one character for one, and the kept span is the paragraph's own (:137-162).- Tests cover both directions.
- Logs: the route logs the error's name, message and stack only (
server/src/routes/content-pages.js:241-246), and a test checks this.
The cap matches #1451. The claims stop once the draft has made 50 Quality calls that day, and the sources stop at 90, so the sources always have 40 left.
Looks good.
00266, now with missed, dry-runs cleanly on prod after 00264. Apply 00264, then 00266, before the server runs with CONTENT_QUALITY_PHASE=2.
Summary
Quality Phase 2, CE-045 "Claim detection in user text", part a: the server. Part b (the editor: Trust counts the claims, a red wavy underline on one with no source, Quality's Show / Remove) comes next. Stacked on #1451 (the
qualityAI feature,holdUsd, the "AI check" tag); review that first. Everything sits behindCONTENT_QUALITY_PHASE=2.What it reads
POST /api/content-pages/claims{ draftId, skip? }reads the draft as saved.trustBlocks): paragraphs, list items, quotes and table cells with their own words, with the editor's spacing for line breaks and sibling paragraphs. Each block from 12 characters on ("Award-winning support") is read once.number: a figure, price, count or date given as fact;stat: what research or a survey found;superlative: best, fastest, fix(tracking): keep job active until webhook results drain #1;fact: an award, a certification such as SOC 2, a product property such as "waterproof", a fact about a company.{ paragraphs: [{ text, claims: [{ text, kind }] }], pending, limited }, only blocks with claims. The editor finds each claim's block by its words.skipis the block the person is writing in (as saved): it isn't read until they leave it.What it keeps (00266
content_quality_claims)anon/authenticatedgrants.Cost
quality, with a hold of $0.004.QUALITY_CALLS_PER_DAY= 60 per draft (content-quality-calls.js), shared with feat(content): read the kind of a source's site the rules can't place with AI (CE-046, part b) #1451's source kinds. Claims stop 10 short (LEFT_FOR_SOURCES), so they never starve the source reads. This changes feat(content): read the kind of a source's site the rules can't place with AI (CE-046, part b) #1451's "30 reads a draft a day": source reads now share 60 with claims.claimsLimiter, 30 per 15 minutes per user), apart from the source kinds' bucket.Logs carry no page words (error name and message only).
Related issue
Quality spec (Drive), Phase 2, CE-045 (part a). Stacked on #1451.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
CONTENT_QUALITY_PHASE=2inserver/.env.POST /api/content-pages/claims { draftId }as a member. It answers both blocks with their claims (superlative,fact).prompt_improve_usagegets no newqualityrow). Change one block and ask: only that block is read.skip: it waits.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no web changeyarn typecheckpasses (run fromweb/): no web changeyarn format:checkpasses (run fromweb/): no web change00266 is applied on the dev DB and
schema.sqlis rebuilt. Server:npm run format,npm run lintandnpm testpass (2,425 tests). A pre-push review's points are in (blocks as the editor's, spacing, short items, size-based calls, missed answers kept as read, the cap left to sources, own limiter, version in the hash, no page words in logs).🤖 Generated with Claude Code