Skip to content

feat(content-editor): hand a brand's imported and agent-written pages off on their own, and list hand-offs in History (CE-051, part 4) - #1490

Merged
gkhngyk merged 102 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-handoff-auto
Oct 25, 2026
Merged

gkhngyk merged 102 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-handoff-auto

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Quality Phase 2, CE-051, part 4: the automatic hand-off and History. This is the last part of CE-051.

Stacked on #1484 (the Hand off card) with #1482 merged in (the Settings › Content switch). This PR's own change is the last commit. Everything is behind CONTENT_QUALITY_PHASE=2.

The spec (§5) has Settings › Content › "Hand off quality fixes automatically" (default off): new and optimized pages get the agent's hand-off run, with the changes left for review. #1481 added the API and the once-a-draft claim (content_agent_runs_auto_handoff). #1482 added the switch, which a draft copies when it is made (content_drafts.quality_handoff).

Automatic hand-off (_use-auto-hand-off.ts)

Only the browser reads Quality, so the run starts in the editor, once a draft. It starts when:

  • the draft's qualityHandoff is on (getContentDraft now reads quality_handoff), the brand still hands off, and the draft isn't published;
  • its page came from elsewhere: imported to optimize (method: 'optimize') or written by the agent (author: 'agent'). A page the person starts empty has nothing to hand off when it opens;
  • Quality is settled and nothing holds Hand off: no open suggestions (Start's are decided first), the agent isn't at work, the month's AI usage isn't spent (it waits, and the card says why), the page's reads are in, and the HTML view is closed;
  • the draft hasn't had its automatic run. The editor reads that, and the brand's current setting, through RLS (readAutoHandOff). An unreadable answer counts as "had", so the run never happens twice.

Then:

  • It runs once a session. With nothing to fix the first time it could run, none runs that session.
  • The server's row is the claim. A second tab or a reopen gets 409 already, and a brand that turned the switch off since gets not_due.
  • The person didn't start this run, so when it doesn't run or finds nothing, the editor says nothing (it only logs). A success says how many changes it suggested, as Hand off does.
  • The run is Hand off's own: the same items, agent card, steps and Stop. Its changes are one batch of suggestions to review.

History lists the draft's hand-offs from the last 90 days among the versions, by time:

  • "Handed off to Content Agent" or "Handed off automatically";
  • how many checks it was given and how it ended: suggestions to review, nothing it could change, stopped, didn't finish, or under way. A run stopped before its outcome was written reads as stopped. One left behind by a stopped server, past RUN_STALE_MS, reads as didn't finish.

There's nothing to restore on these rows: their changes were suggestions, and the page before the first accepted one is already a version. getDraftHandoffs reads them through RLS; if that read fails, the versions still show.

Pre-push review fixes:

  • quiet errors for the automatic run;
  • no run on a published draft or for a brand that turned the switch off;
  • History's stopped and stale rows;
  • the "nothing it could change" note;
  • sorting by time rather than by the timestamp text.

Docs: the Quality tab isn't in the guide yet (it's behind the phase flag). Hand off goes into the guide with Quality when phase 2 goes live.

Related issue

Quality spec (Drive), Phase 2, CE-051 (part 4). Stacked on #1484, with #1482.

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. Run feat(content): hand a draft's open Quality checks to the Content Agent in one run (00275, CE-051, part 1) #1481's API (00275) with CONTENT_QUALITY_PHASE=2 on both sides. Turn on Settings › Content › "Hand off quality fixes automatically" for a brand.
  2. Start a new draft by importing a page (New content › Optimize, by its URL) that has a few long sentences.
  3. Open it in the editor. Once Quality has its scores, the agent card shows the hand-off running by itself, and its changes arrive as suggestions to review.
  4. Reload the page: it doesn't run again. Open History: "Handed off automatically · N checks · its changes were suggestions to review" sits between the versions.
  5. With the switch off, or on a draft you start empty, nothing runs on its own. Hand off on the Quality tab still works.

The browser check (both themes, 1024 px) is still owed, batched with the other Quality P2 PRs.

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 test (3,767 passed) and yarn build pass.

🤖 Generated with Claude Code

cihan-gyk and others added 30 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]>
… 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]>
…roduct pages, kept for approval (00269, CE-047, part a)

Quality phase 2, CE-047: the brand's prices and plans, trial, founding
year and claims, read from its own site for Trust's "consistent with
brand facts" check. The model finds the facts and copies each one's
words; a fact is kept only when its words are on the page as written,
and its value (amount, currency, period, days, year) is read from them
by rule. A person approves each one.

- 00269: brand_facts (members read, and change only the status, as
  themselves) and brand_fact_pages (server-only: a hash of each page's
  text, so an unchanged page isn't read by the model again; no text
  kept).
- brand-facts.js: findFactPages (page list, Site trust's About page,
  else probes on the main domain; never Scrape.do), factText, keptFacts,
  refreshBrandFacts (new values pending, approved ones gone from the
  site marked gone, pending ones dropped), readBrandFacts (first ask
  reads, asking again every 10 minutes at most), setFactStatus.
- GET /api/brand-facts, POST /fetch, PATCH /:id behind phase 2, with
  their own limiter; logs carry no page text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…47, part c)

Brand settings › Brand facts, with Quality's phase 2: the facts the API
read from the brand's own pricing, About and product pages, each with
its words on the page, where it was read and the approved value it would
replace ("Was $59"). A member approves or rejects each one (no approve
all: the spec has each approved); approved facts no longer on the site
say so. Each page's read is listed (read, not found, turned our reader
away, didn't answer); Read again reads the site again once the API
allows it, and a spent AI budget says so. `?tab=facts` opens the tab,
for the editor's to-do to link to.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… still has, and store no wrong price (CE-047, part a review)

- factText walks the page once and stops near MAX_TEXT_CHARS: a page of
  100k blocks reads in well under a second (was quadratic). Struck-through
  old prices (del, s, strike) are left out.
- A fact still on any page read (its words, a price's with its plan near
  them; across a card's lines too) stays; only facts whose page was read
  and has them no more are marked gone or dropped, written once.
- A plan's name is found on the folded text without lowering it (a
  Turkish "İ" lowers to two characters), and a quote only where it
  doesn't run into a number ("$49" in "$499", "$1,2").
- parsePrice reads one price only, no saving, discount or old price, a
  dollar named by its code after it ("$49 CAD"), and the period in the
  words right after it, the first named ("Lifetime access, monthly
  updates" is once). Magnitudes in any case; a trial needs a trial word,
  "started in" is no founding year.
- A page read after a wall or a failure says "ok" again; a missed
  answer's hash isn't kept past a failed read. A changed page goes to the
  model once an hour at most (MODEL_EVERY_MS). A page that failed (or a
  spent budget) is read again at the next ask after RECHECK_MS.
- Facts are written before the pages' hashes; source_url is cut to 2048.
- A listed page that no longer answers falls back to the usual
  addresses; a probe that is the home page again isn't read as one.
- readPage maps not-HTML, refused and redirect-loop reads to not_found;
  401/403/429 to blocked, 5xx to failed. setFactStatus answers 404 for a
  fact removed meanwhile.
- GET has no bucket of its own (the editor reads it as its tab comes
  back); POST /fetch keeps brandFactsLimiter.
- 00269: each kind's value checked (amount ≥ 0, currency, days, year),
  source_url http(s) only, a member's reviewed_at within a minute of now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Trust, with an Approve to-do (CE-047, part d)

Trust's "consistent with brand facts" (10 points, phase 2): the page's
prices, trial and founding year against the brand's approved facts still
on its site, read so as not to cry wolf: a price in its own currency
only, against a plan's prices (any of them: monthly and annual billing
both count) when the sentence names the plan, else only when it names
the brand (or "we") with a period; "from $29" against the lowest price;
no sentence naming a competitor; discounts, scales and ranges aren't
prices. Like a working link, it doesn't score Trust on its own.

- A mismatch is Quality's suggestion, "Price differs from brand facts ·
  Page $39 · pricing page $49", with Show on its sentence.
- "Approve {n} brand facts" is the person's to-do while facts wait, with
  Review linking to Brand settings › Brand facts (the to-do row and the
  next-step nudge, not Settings › Authors).
- useBrandFacts reads them once with phase 2 and again when the tab
  comes back from Brand settings; the next-step reads wait for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… after a review, and do one thing at a time (CE-047, part c review)

- settings/layout.tsx sets maxDuration 300: the first read and Read
  again wait while the API reads the site (pages, then the model).
- A review updates the list in place (no read that could read the whole
  site again); a failed one reads the list as kept, a fact a read
  removed meanwhile gone from it. Approve, Reject and Read again don't
  run at once; the row being saved says so (aria-busy).
- An API with brand facts off says they aren't available yet; a thrown
  action shows the failure instead of loading for ever.
- Page links read as the page's name; sections are labelled by their
  heading; the quote marks and the page status separator are messages;
  "missed" and the paused note say when the read comes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…after a price, and read brand facts once at a time (CE-047, part a review 2)

- A page under 200 characters (one its scripts write, a wall not told
  apart) leaves its facts as they are on every read, not only the first.
- A currency code or a scale right after a quote is read ("$49" then
  "CAD per month" is CAD; "$2" then "million" is no price); only "off"
  right after a price drops it (the next card's "Save 20%" doesn't). A
  period is named within 24 characters of the price, the first one
  named; "per active user" is per seat.
- A plan's name matches as whole words ("Pro" isn't in "Product"); a
  quote isn't taken inside another mark's dollar ("C$49") or a
  space-grouped number ("299 €" in "1 299 €").
- factText counts words toward its length, not indentation.
- A page whose model read failed waits MODEL_EVERY_MS like any other;
  a GET reads a failed page again behind its answer, not before it.
- New facts get the room the removed ones leave; a page whose new facts
  didn't fit keeps its old hash, to be read again. A kind no longer read
  (a shop's product page) loses its row.
- refreshOnce: one read per brand at a time, for the tab and the weekly
  read alike.
- 00269: a missing key is a check violation, and numbers compare as
  numeric (no cast error).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…de the price, the brand's own trial and founding year only (CE-047, part d review)

- A price is compared with the plan named nearest it, its name as the
  page writes it (case too); a plan that is an everyday word ("Pro",
  "Team", "Free", "Growth") only beside "plan"/"tier" or with the brand
  named. With no plan, only a sentence naming the brand and saying what
  it costs; no "we/our" path. Free ($0) is never compared; "from $19"
  matches any approved price.
- A sentence with an old price, a saving, a discount, credits, tax or a
  team's bill ("was $49", "incl. VAT", "5 users pay") isn't read for
  prices; "billed monthly/annually" narrows to that billing.
- Ranges need a number before the dash or word (French "à", Turkish
  "ile", "between … and"), so "Pro – $49" is a price again; an amount
  doesn't start inside a number.
- A trial is compared where it is the brand's ("your free trial",
  "every plan", its name), its days right beside the trial; a founding
  year right after "founded", with the brand named or "we were founded".
- Each sentence once. The to-do is last (the brand's, no points of the
  page's), "Review your brand facts" at 0 and "reviewed" when done.
- useBrandFacts fails instead of loading for ever when the action throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 24 commits October 25, 2026 09:42
…rkspace, say what turning it off does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, in one run (CE-051, part 3)

Quality has a Hand it off to Content Agent card under its scores: it sends
every open suggestion (ansvisor#1481's fixable checks), each with what it names on
the page, and the agent leaves its fixes as one batch to review, on the
same card, steps and Stop as Fix open rules; the to-dos stay the person's.
The disclosure goes only with its line in the page's language.

Fix open rules and Hand off share what they send besides their items
(agentContext) and how their answer is told (runAgentFix).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…card on its own run (CE-051)

- A suggestion that asks the other way to its check (sentences too short,
  a page too simple) stays the person's: the agent is told shorter and
  easier.
- Fix open rules and Hand off each show their own run; the other card
  waits, saying the agent is at work.
- The disclosure isn't sent once its line is on the page; Hand off waits
  for the page's read after a save when it sends what AI read
  (usePageRead's behind), and while claims are read.
- The passage is cut to fit, never the disclosure line.
- A full hand-off says to hand it off again; the API's 'off' is said.
- The blocked reason is the button's description.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne fix at a time (CE-051)

- dropsPlaceholder counts each placeholder before and after the change,
  read in what is kept (the new words and the blocks after them): filling
  one of two "[figure, source]" in a passage is dropped too. In a heading
  only the agent's own forms count, as the editor reads them.
- A hand-off's prompt says to leave every [placeholder] as it is.
- Fix open rules and a hand-off are refused with 409 `running` while
  another fix or hand-off on the draft is under way (fixUnderWay).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd-facts-check

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx
#	web/src/lib/content/quality-todos.test.ts
#	web/src/lib/content/quality-todos.ts
…nd a trial only after the brand's (CE-047)

- A named plan's price is read as the brand's is: right after its name
  (with its plan or tier word), with nothing, "is", a colon, a dash, "("
  or a pricing verb between. A price compared within a few words after it
  ("$30 more than", "$20 less … than") is read for no one, and "saves",
  "saved", "saving" are a saving.
- In a part of the sentence that is the brand's, only a trial length after
  its name or "your trial", "every plan" is its own; "free for N days" is a
  trial only after "try"/"use" and the brand, or in a sentence that says
  "trial".
- "We were founded" starts its clause only at the sentence's start or after
  since/when/after/and, not after a colon (quoted speech).
- In phase 2, the Quality score also waits for the brand's facts.

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

# Conflicts:
#	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/content/quality-todos.test.ts
#	web/src/lib/content/quality-todos.ts
…s read for proof (CE-049)

usePageRead counts a save it hasn't asked about yet as reading, as
useClaims does, and waits only for changes on their way (the editor's
narrower `saving`), so a failed save, a conflict or a page too large
doesn't hold it. In phase 2, qualitySettled waits for the page's read.

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

# Conflicts:
#	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/quality-todos.ts
… score when the own images can't be read (CE-049)

- qualitySettled waits for E-E-A-T's visual proof in phase 2 (the page's
  read and the own images), so the chip doesn't settle on Trust and
  Readability and move when the read lands. The page read already waits
  only for changes on their way (ansvisor#1468's `saving`).
- A failed own-images call counts the confirms made so far, so E-E-A-T
  scores and Confirm opens.
- The visual proof to-do is listed when Your input can't be read too, in
  its place.
- E-E-A-T takes both the visual proof and the author confirmations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	supabase/schema.sql
#	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/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
#	web/src/lib/actions/content-drafts.ts
#	web/src/lib/content/quality-todos.ts
# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_quality-tab.tsx
#	web/src/lib/content/quality-checks.ts
#	web/src/lib/content/quality-todos.test.ts
#	web/src/lib/content/quality-todos.ts
…age is read again (CE-050)

- aiChecksOnPage holds a find whose paragraph changed while the page as it
  is now is still to be read: changes not saved yet, a save not asked
  about (usePageRead's reading, ansvisor#1468) or an ask out. The passage that puts
  the brand forward still applies then, and Answer first's verdict is held
  (`held`, which readability takes over the block match).
- The editor, a save and a restore detect the page type with the existing
  page's address, as Start did, so the read's type and the editor's agree
  from the start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
…ount it before the next read (CE-050)

- Add line looks for the opening paragraph past what has no words (an
  image, an empty paragraph), as Readability and the page read do, and a
  byline or a date: the answer stays first for Answer first.
- While the page has the line Add line put in, the disclosure counts as
  found (Trust, Quality's suggestion, Export's line); Before you publish
  still says it was added until the page is read again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	supabase/schema.sql
#	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/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-page-read.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-page-read.ts
… Hand off sends, and say `running` (CE-051)

- usePageRead's reading now counts a save not asked about yet (ansvisor#1468), so
  the hand-off's own `behind` flag goes. Hand off waits for the page's
  read before its first answer, or after a save while it sends what AI
  read of the page (Answer first, the disclosure, balance); not after
  every save.
- The API's 409 `running` (another fix or hand-off on the draft, ansvisor#1481)
  is said, for Fix open rules too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… off on their own, and list hand-offs in History (CE-051, part 4)

- A draft its brand hands off (Settings › Content, copied at creation,
  quality_handoff) whose page came from elsewhere (imported to optimize,
  or the agent's) goes to Hand off on its own, once: when Quality is
  settled and nothing holds Hand off (open suggestions, the agent at work,
  a spent AI budget, the reads, the HTML view). The editor reads whether
  the draft had its automatic run (readAutoHandOff); the server's row is
  the claim, and its `already` / `not_due` aren't said.
- History lists the draft's hand-offs of the last 90 days among the
  versions by time, who started each, how it ended and its checks, with
  nothing to restore (getDraftHandoffs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hed pages, and read History's hand-offs as they ended (CE-051)

- The automatic run says nothing when it doesn't run or finds nothing
  (only logged); a published draft, or a brand that stopped handing off
  (readAutoHandOff reads its setting too), doesn't run it at all.
- History: a run stopped before its outcome was written reads as
  stopped, one left past RUN_STALE_MS as failed; a done run with no
  change says so; rows sort by time, not by the timestamp's text.

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 25, 2026

@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.

What I checked:

  • When it runs. Only with phase 2 on in both the web app and the API. Only on a draft whose quality_handoff was copied on when it was made, while its brand still hands off. Never on a published page: the editor checks, and the API refuses published before it takes the claim. Only imported (optimize) and agent-written pages. When the agent writes a draft from the editor, the editor opens again on the new draft, so the hand-off follows right after the write.
  • Once, and never two at a time. The hook starts it once per mount. The API's run row is the claim (unique index content_agent_runs_auto_handoff, on prod). A second tab gets running or already. Refusals that come before the claim (running, open_suggestions, writing, a spent budget) leave the draft free, so it runs the next time it's opened.
  • Cost. It waits while the month's AI usage is spent (the card's blocked). If the usage hasn't loaded yet and is spent, the API refuses and takes the claim back. A draft that already had its run costs two small reads each time it opens. The History read uses content_agent_runs_draft_started.
  • Nothing applies on its own. The run leaves one batch of suggestions, and none of them is accepted for the person. The page is saved first, as Hand off does.
  • History. Rows are read through RLS (only members of the draft's organization), listed by time among the versions, without Restore. The step keys match the server's hand-off steps (read_checks, and write_changes set when it's done). A run stopped before its outcome was written reads as stopped, and a stale one as didn't finish. If the hand-offs can't be read, the versions still show.
  • Without the setting. A draft that isn't flagged makes no read and no run. If its brand turned the setting off since, the draft counts as had, and the API answers not_due.
  • Merge commit 641d03c changes nothing beyond merging its parents. The PR's own change applies to main as is: main's other change to en.json is in a different section.

Low, follow-up (please fix before phase 2 goes on):

  1. web/messages/en.json:7129: the hint in Settings › Content says "Pages made while it's on get the Content Agent's quality fixes when they're first opened in the editor". This PR hands off only imported pages and pages the agent writes. A page the person starts empty is flagged but never handed off. A page with nothing to fix the first time it's opened can still be handed off on a later open. Say which pages, e.g. "Imported pages and pages Content Agent writes, made while it's on, get its quality fixes in the editor; …".
  2. _draft-editor.tsx:1783-1784 and :1832: keeping refusals quiet is right (already, not_due, running, open_suggestions, a spent budget). But failed, an answer that never lands, and "nothing it could change" come after the person has watched the agent card run, and then the run ends without a word. A failed automatic run also keeps its claim, so it never runs again, and nothing tells the person to hand off by hand. Report those outcomes as Hand off does. Also, nothing says the run started on its own, so a member who didn't turn the setting on sees the agent start by itself. One line on the card or in the success toast (for example "Handed off automatically · Settings › Content") would explain it, and could say it counts toward AI usage. With refusals quiet, fixErrors.not_due and fixErrors.already (en.json:3898-3899) can no longer show, so drop them.
  3. web/src/lib/content/agent-runs-client.ts:42: only an automatic run counts as had. Say a person has already handed a draft off because the first chance found nothing or was refused. On a later open, the draft still gets an automatic run, which is charged again for checks the agent already tried. If a person's run should end the automatic one, count any hand-off on the draft (drop .eq('origin', 'auto')).
  4. _draft-editor.tsx:2017-2021: an archived draft still opens in the editor, and opening one hands it off. Add !draft.archivedAt to due.

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 25, 2026
@gkhngyk
gkhngyk merged commit 17de88c into ansvisor:main Oct 25, 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