Skip to content

feat(audit): read a brand's site trust: About, Contact, editorial policy, Organization schema and author pages (CE-043) - #1417

Merged
gkhngyk merged 122 commits into
ansvisor:mainfrom
cihan-gyk:feature/site-trust-server
Oct 23, 2026
Merged

gkhngyk merged 122 commits into
ansvisor:mainfrom
cihan-gyk:feature/site-trust-server

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Content Editor Quality spec §8, CE-043 Site trust: server part. It reads a brand's five site-level checks:

  1. About page
  2. Contact page
  3. Editorial policy (or "How we review") page
  4. Organization schema on the home page
  5. Author pages for the authors in Settings › Authors

Site Audit shows the result as "Site trust {n}/5", and it is worth 5 Trust points on every page. The web part (Site Audit card, Quality line and Trust points) is the next PR, stacked on this one.

Stacked on #1416 (→ #1415 → #1414 → …). Deploy order: migration 00259, then the server, then the web PR.

GET /api/audits/site-trust?brandId=…&refresh=1 (before /:id, with assertBrandAccess) returns the day's read, or a new one.

server/src/lib/site-trust.js

  • Where it reads. Only the brand's own site:
    • The brand's page list (site_pages). Pages whose last read answered ≥ 400 are skipped.
    • When the list has no About, Contact or editorial page, /about, /about-us, /contact, /contact-us, /editorial-policy and /how-we-review on the primary domain. Each goes through the guarded fetchPage (1 MB, 8 s).
    • A page that redirects off the site isn't read.
  • What counts as the page:
    • From the list: the address's last part (/about, /company, /hakkimizda…, in the languages the app reads), or a title that is just that ("About us · Acme", not "About our pricing changes").
    • From a tried address: it must not be the home page again (same title and H1, which catches sites that answer every address with their home page). Its address or title must be the page's, so /about → /company/about also counts, and its title or H1 must have the word.
    • Organization: Organization, its kinds, …Organization / …Business types and common local ones (Restaurant, Dentist, Hotel…), with or without the schema.org prefix.
    • Author pages:
      • Which authors: the ones this brand's pages are by plus its default author, else the workspace's.
      • What counts as a page: one in an author folder named for them (/authors/ada-lovelace, /team/…, /yazar/…), or one titled just their name, or a profile link of theirs on the site. A post about them doesn't count.
      • With no authors, the check fails (the card sends you to Settings › Authors).
  • How it runs:
    • The checks are read in parallel, and two asks for the same brand at once share one read.
    • A read is kept for 24 h. "Check again" reads again at most every 10 min.
    • A read the site didn't fully answer (timeout, unreachable, 5xx) is marked complete = false and read again after 10 min, so a slow home page doesn't cost the brand 5 Trust points for a day.

Migration 00259_site_trust.sql: site_trust (brand_id PK, checks jsonb, score 0–5, complete, checked_at). RLS lets members of the brand's org select. Grants are revoked from anon and authenticated, select goes to authenticated, and all to service_role. The server writes.

Pre-push review:

  • The first review asked for the parallel reads, the home-page and redirect guards, anchored titles and author folders, partial reads, brand-relevant authors, dead pages, more organization types and the grants. All are in.
  • Second-level product question: the "authors" for the author-pages check are the brand's own (drafts + default), falling back to the workspace's. Say if you'd rather use all of Settings › Authors.

After review (2026-10-23):

  • Bot walls: a 401/403/429, or a 200 challenge page by its title or H1, is an unsure read (complete = false).
  • Scrape.do: a walled home page is read once through it, unrendered, at most once per brand per day. A new nullable site_trust.scraped_at in 00259 keeps it to that. Without SCRAPEDO_API_KEY it stays unsure.
  • Author pages: when the page list has no match, /author/<slug> and /authors/<slug> are probed for up to 3 authors.
  • complete is returned next to checks, score and checkedAt.

Related issue

Drive spec Quality §8, CE-043. No GitHub issue.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

How to test

  1. Apply 00259_site_trust.sql.
  2. GET /api/audits/site-trust?brandId=<brand> with a member's token. You get checks, score and checkedAt, and a second call within a day answers from site_trust.
  3. Add /about and /contact pages to the brand's site_pages (titles "About us", "Contact"). Then call with &refresh=1 (more than 10 minutes after the last read): they pass.
  4. Brands of another organization get 403.

Checklist

  • npm run format, npm run lint, npm test in server/: 187 files, 2,239 tests, at the top of the stack with the web PR
  • Tests:
    • site-trust.test.js (13): page finding and false positives, organization types, author pages, the home-page and off-site guards, partial reads, brand-relevant authors, TTLs, one read for two asks
    • route tests for /site-trust
  • Migration added, schema.sql rebuilt, applied on the dev database

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 23, 2026 02:24
The workspace's one AI budget (Improve, the Content Editor's AI and the
Action Center's task writer) had no meter: the first sign of it was an
"AI usage is used up" error. Migration 00242 records what each AI call
was for (prompt_improve_usage.feature, backfilled) and sums the period's
spend by feature (ai_usage_by_feature). GET /api/billing/ai-usage
returns the shares of the plan's budget, and the Billing page shows the
share used, when it resets and what used it, with Agent Chat noted as
running on the workspace's own key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The workspace's AI budget was checked by reading the period's spend; the
call's cost was written once the model answered. Calls running at once
(two tabs, a teammate, an Action Center sweep) all read the same spend
and all ran past the budget. 00243's reserve_ai_usage takes a
per-organization lock, reads the spend with the calls in flight, and
holds the call's estimated cost; reserveAiBudget turns the hold into the
real cost or releases it. Improve, the brief rebuild, Apply rules with
Agent, Start Agent and the Action Center task writer use it in place of
enforceImproveQuota, which goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes:
- Apply rules with Agent and Start Agent charge an answer the provider
  billed but that missed the schema (NoObjectGeneratedError), as Improve,
  the brief and the task writer do; before, the hold was let go and the
  call ran free.
- A call holds the org's median cost over its last 20 calls this period,
  never less than the model's typical cost, so calls in flight pass the
  budget by far less.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply rules with Agent makes at most 8 small edits a run, which can't
bring a long page to its Length (about 2% a run on prod). The Content
Agent can now rewrite the whole page in one background call, left as ONE
suggestion (kind 'page', migration 00247) to compare and accept or reject:
- POST /api/content-drafts/:draftId/rewrite, through Start Agent's claim,
  budget hold and background run;
- passages AI quotes today, tables, images, quotes and HTML blocks go to
  the model as [[KEEP n]] lines and come back as they were; a rewrite that
  drops one fails the run;
- one H1, only the page's own links and the ones offered, the editor's
  tags; the page as it was is kept on the suggestion (before_html).

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

Review fixes:
- Kept blocks are described under the page (a quoted passage's words, a
  table's rows, an image's alt) and their text counts toward Length, so a
  rewrite aims at the whole page's length; with Length off it keeps the
  page's own. A kept H1 stays first, and the page's language is kept.
- The answer is taken out of a code fence, text left at its root goes in
  paragraphs, and an answer in Markdown fails the run.
- The page's own links stay exactly as written (query and anchor too).
- Kept blocks go back untouched (an empty table cell stays), only the
  page's first H1 counts as its title, a page that writes "[[KEEP" gets
  markers of its own, and a page that is only kept blocks isn't sent.

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

The Rules tab opens with the agent's two ways to meet its rules: Apply
rules with Agent (small edits, up to 8 a run) and Rewrite the page to
these rules (the whole page as one change). The rewrite is recommended,
with a one-line reason, when the page is more than 30% off its Length or
4 rules or more are open.

A rewritten page comes back as one suggestion with its own bar over the
page: the characters before and after and the agent's reason, Compare
(the page and the rewrite side by side), Accept (History keeps the page
first), Reject, and Undo. A page that changed since the agent read it
isn't written over. The page waits for the rewrite with its own steps,
and a failed rewrite's Try again rewrites again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes:
- A page is compared with the one the agent read by its words, with a
  space between blocks, so stored line breaks and lists don't read as a
  change (Accept and Undo were refused on imported pages).
- One agent run at a time from the page; a rewrite never starts before
  the locked passages are read, and sends the editor's own locked keys.
- Accept holds the page still from the start and checks it again before
  putting the rewrite in; Undo puts the page back as it was (two H1s too),
  and the bar waits while the HTML view is open.
- No rewrite advice for an empty page or one too long to send whole; the
  rewrite mark survives a reload; the waiting view says the rewrite waits
  in the editor; Compare's links don't navigate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1, part 1 (CE-025, CE-026, §4): the agent row and the
rewrite bar become one card above the toolbar, in three states:
- waiting: "Content Agent has {n} suggestions for you", what they change
  and the rules they gain ("Rules 5 → 6 of 13"), with Review (scrolls to
  the first suggestion and marks it), Reject all and Accept all; a page
  rewritten shows its characters, with Compare;
- all reviewed: what was accepted and the rules met and still open, with
  Undo all and Run Agent;
- working: while Apply rules with Agent runs.
The tile moves a little (a soft ring, a blink, a spark; a sweep and a
breath while working), never a rotating ring, and not at all with reduced
motion. The card wraps on a narrow page; Accept all and Run Agent are the
primary buttons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Run Agent on the card keeps to one agent run at a time and says why it
  waits; Apply rules never starts beside another run or before the locked
  passages are read.
- Ghost buttons show their hover on the card's grey; the tile and its
  count are hidden from screen readers (the title says it) and the count
  is darker for contrast; "+N more" comes from en.json, the reason's first
  letter is upper-cased in the page's locale.
- Review picks the first open suggestion in the page's order and focuses
  it; the sweep shows on the light tile in dark mode; the spark is slower
  once all are reviewed; without motion the working line is a faint full
  line; "0 still open" isn't said.
- globals.css keeps its own lines; only the motion block is added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…split Run Agent

Content Editor v1.1 part 2 (CE-028–CE-031): the side panel's tabs become
Instructions · Sources · Live page. Instructions holds Brief | Rules, with
the rules still open on the tab and the segment. Each segment opens with a
status card: Rules has one split Run Agent ▾ (Fix open rules, or Rewrite
the whole page, which renames it "Rewrite page") in place of the two rule
buttons; Brief has Run Agent while empty and Rebuild brief once written.
Why the agent can't run is written under the card, and each card's ⓘ tip
opens below it. The brief shows "Not set yet" and its Length in characters
and about as many words; the toolbar counter adds the page's words.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Run Agent's choice is worked out once and falls back to Fix without a
  rewrite; once a rewrite starts, the button is back on Fix.
- ▾'s choices are menu radio items; Fix is off when only rules the agent
  can't fix are open, and the card says what to do instead.
- The reason line under the card stays mounted for screen readers; Rewrite
  from brief writes its reason too; the tab's count is read out.
- Brief | Rules switch with the arrow keys, one tab stop.
- An edited brief's rebuild question sits under the card; a brief without
  H2s says to rebuild it; an empty brief shows no origin line.
- Plural copy for the open suggestions and the counter's words; rule names
  joined by the formatter; Run Agent's tip leaves ▾ out without a rewrite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1 part 3 (CE-032, CE-034): under each Run Agent card,
"Uses your data: 1 prompt · 21 fan-outs · 20 cited pages · 10 Search
Console queries · Edit sources", counted as the Sources tab keeps them, so
turning one off lowers it at once. The Sources tab carries its count, and
its top says "N sources in use" and when the Content Agent last wrote from
them (its latest suggestions or the brief it built). A first visit's note
at the top of Instructions says the agent writes from the person's data;
closing it is kept in their own user metadata.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- "Last used by Content Agent" also counts the agent writing the page
  (agent_state_at: Start with Agent, Rewrite from brief on a new page),
  not a run that failed; a value that isn't a date is skipped.
- The latest batch's time is its first suggestion's, not a sort per render.
- Tests: the Brief segment's line, no line while the sources can't be read,
  the tab's count, the note showing again after a failed write, and a
  suggestion read with its createdAt.

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

Content Editor v1.1, CE-033 (server): Fix open rules, Start with Agent and
Rewrite the whole page read the sources the Sources tab keeps, numbered
S1, S2… (content-sources.js). Each suggestion keeps the sources it names
and the words each supports (content_draft_suggestions.sources and
source_marks, 00248); a page rewritten whole keeps its sources.

No number without a source: the model reads a source by its words only, so
a number the agent adds must be the page's, the brand's, the brief's, the
rules', today's, or in a source's own words (then marked to it). A
suggestion with any other number is not kept; a page written whole gets a
placeholder in its place. Source numbers written into the words are taken
out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1, CE-033 (web) and the rest of CE-034: under each
suggestion, "Based on" chips name the sources it used (number, kind, name;
the Sources tab's details on hover), and a small number marks the words
each supports. A click on either opens Sources on that row, scrolled to
and ringed for a moment, once. The agent card adds "built from N of your
sources · See sources". Fix open rules sends the kept sources, and the
first-visit note says every change shows the sources it used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1, CE-027/035 (server): each Content Agent run (Fix open
rules, Start with Agent, Rewrite the whole page, the brief) is written in
content_agent_runs (00249) with its steps named by the data it reads
("Reading 20 cited pages", "Matching 21 fan-outs", "Writing 3 changes") as
it reaches them. POST /api/content-drafts/:id/stop marks the run stopped
and aborts its model call; the run checks before it keeps anything, so a
stopped run changes nothing (no suggestions, page, brief or History).

A run that can't be written still runs; runs a stopped server left are
closed when the next starts, and Stop ignores them. Background runs are
written before Start answers, so Stop finds them at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stop also clears the draft's 'writing' state at once: a background run lets
go once it sees the stop, but one no server holds any more never would, and
the waiting page would wait out the 10 minutes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p it (CE-027, CE-035)

The agent card, the brief and the waiting page show the run's real steps
(content_agent_runs, read from the browser every second) and a Stop button
that ends the run through the API proxy, leaving the page as it was. A dashed
decoration under the H1 says where Fix is drafting, and the agent's dots
replace every spinner on its buttons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h (CE-030)

When the brief is rebuilt, the server reads the first few cited pages kept
in Sources (only addresses AI answers cited for the brand, never the draft's
own page), counts their main text as the Rules tab counts length, and saves
the median as brief.citedLength. The Brief tab says "From the rules · cited
pages average N characters"; with fewer than two pages read it stays "From
the rules". textLength moves to page-content.js to avoid an import cycle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	server/src/lib/content-writer.js
#	server/src/lib/content-writer.test.js
#	supabase/schema.sql
…le it writes

content_drafts.agent_run ('write' or 'rewrite', in 00247 and its guard) is
set when Start or a rewrite claims the draft, so every device knows a failed
rewrite from a failed Start. Fix open rules and the MCP suggest call answer
409 'writing' while a run holds the draft, so its answer is never dropped
after it was charged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le it writes

content_drafts.agent_run ('write' or 'rewrite', in 00247 and its guard) is
set when Start or a rewrite claims the draft, so every device knows a failed
rewrite from a failed Start. Fix open rules and the MCP suggest call answer
409 'writing' while a run holds the draft, so its answer is never dropped
after it was charged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st batch's rows

The editor reads content_drafts.agent_run, so a failed rewrite is tried again
as one on every device (the localStorage mark is gone). Fix open rules' new
409 'writing' says the agent is already writing. getDraftSuggestions finds
the latest batch first and reads only its rows, and Compare's links can't
take focus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The card's Run Agent writes its reason in the card's second line (amber, tied
to the button by aria-describedby) instead of a hover title, and is turned
off when the only rules left open are ones the agent doesn't fix (one H1),
as the Rules card does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 24 commits October 23, 2026 23:04
…, and score Trust only with a figure or a dated source

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h Scrape.do once a day, and look for author pages at the usual addresses

A 401/403/429, or a 200 challenge page, now leaves the read incomplete
instead of failing About, Contact, Editorial or Organization schema for a
day (looksBlocked from site-pages.js). A walled home page goes through
Scrape.do, unrendered, at most once a day per brand (site_trust.scraped_at),
and a pass it read stands for that day while the wall hides the page.
An author the page list has no page for is looked for at /author/<slug>
and /authors/<slug> (a few authors per read), with the probes' guards and
their name in the title or H1. readSiteTrust returns complete, so the web
can tell a partial read from a fix to make.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… sentences where they end

- Japanese, Chinese and Thai, written without spaces between words, get no
  score: Quality says "Readability isn't read for this language yet"
  instead of asking for more paragraphs. Sentences also end after 。!?,
  । and ؟, and a Hindi word keeps its vowel signs, so Hindi is read by its
  own sentences and words.
- The language is the draft's Language rule when it is on, else the
  brand's; every brand language's name is read ("Portuguese", "Brazilian
  Portuguese", "日本語"…).
- A sentence doesn't end before a lower-case word, nor at a German or
  Turkish ordinal ("am 3. Oktober") or a language's common abbreviations
  ("z. B.", "p. ex.", "örn."); one before a number only ("No. 5") counts
  there. A full stop before a closing quote or bracket ends one.
- Show goes to the first copy of a passage, and a second Show within the
  moment keeps its mark for the full time.
- Passive voice reads common irregular participles (sent, found, held…).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-steps-server

Main squash-merged ansvisor#1389 and ansvisor#1393–ansvisor#1399; its tree is ansvisor#1399's last head
(b84e724), so this is that merge: this branch's changes on top of it.
Renumbers our migration 00252→00256, as asked in review: main took 00251 in ansvisor#1425.
Renumbers our migration 00253→00257, as asked in review: main took 00251 in ansvisor#1425.
…heck

Renumbers our migration 00254→00258, as asked in review: main took 00251 in ansvisor#1425.
…rver

Renumbers our migration 00255→00259, as asked in review: main took 00251 in ansvisor#1425.
ansvisor#1400 adds the column to 00249.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed, and main merged.

  1. Migration: 00259_site_trust.sql, its header and the site-trust.js comment. Apply 00256/00257 before this server deploys, as you noted.
  2. Bot walls. 401/403/429 count as unsure (complete = false), using looksBlocked.
    • For a 200 answer, looksBlocked reads only the page's title and H1. A real contact page can load a reCAPTCHA script, which the full-body check would call a wall; there's a test for that.
    • A walled home page is read once through Scrape.do, unrendered, with no retries. Without SCRAPEDO_API_KEY it stays unsure.
    • Incomplete reads are read again after 10 minutes, so a new nullable site_trust.scraped_at (in 00259) keeps Scrape.do to once per brand per day.
    • Meanwhile, an Organization-schema pass from that read still counts while the wall blocks direct reads.
  3. Author pages: when the list has no match, the check probes /author/<slug> and /authors/<slug> for up to 3 authors.
    • The page must not be the home page, must stay on the site, and its title or H1 must have the name as whole words.
  4. complete is returned top-level next to checks, score and checkedAt, for kept and fresh reads alike.

Tests cover each case: bot-wall statuses, a challenge page, the reCAPTCHA page, one Scrape.do call per read, once a day, the carried pass, probes and their guards, the cap, and complete.

gkhngyk
gkhngyk previously approved these changes Oct 23, 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.

All items done. Looks good to merge.

  1. Renumbered to 00259_site_trust.sql. The header and the site-trust.js:14 comment are updated, and schema.sql matches a fresh build-schema.sh.
  2. A 401/403/429 answer, or a challenge page by its title or H1, now counts as unsure. A walled home page goes through Scrape.do once per brand per day (scraped_at), and there are tests for it, including the reCAPTCHA contact page.
  3. Author pages are probed at /author/<slug> and /authors/<slug> for up to 3 authors, with the probe guards and a whole-word name match.
  4. complete is returned for both kept and fresh reads.

The three new merge commits only carry the 00254 → 00255 → 00259 renumbering.

Low follow-ups:

  1. A probe's 403 keeps the read partial for good (site-trust.js:187-191). Some hosts answer a missing path with 403: S3 behind CloudFront without list access, and some WAF rules. On those sites /editorial-policy and the author probes never count as missing. Every read stays partial and is redone every 10 minutes, and the card's rows say "checking again in a few minutes" all day instead of what to add. Suggestion: when the home page answered directly, treat a probe's 401/403 as "not there", and keep 429, 5xx and a challenge page as unsure.

  2. complete is one flag for the whole read. On a partial read, #1418 marks every failing row as not read, including rows that were read. For example, a home page read fine but without Organization JSON-LD shows "didn't answer" because /how-we-review timed out. And behind a wall that doesn't go away, those rows say "checking again in a few minutes" on every read. Two changes would let the card give advice on the rest:

    • mark the checks that weren't read (unread: true on each, or a pending list);
    • say when a bot wall turned the read away.
  3. Authors past the third are never probed (site-trust.js:364). This happens with the workspace fallback: no draft has an author and there's no default. A workspace with more than three authors then fails Author pages from the fourth author on, even when their /author/<slug> page exists. Raise the cap and limit how many probes run at once, or leave unprobed authors out of the check instead of failing them.

Deploy note: 00259 applies on its own (it needs only brands and profiles). The server, though, reads content_authors, content_author_defaults and content_drafts.author_id, so 00256 and 00257 must be on prod before this server deploys. The PR description lists only 00259. Merges cleanly on main.

@gkhngyk
gkhngyk dismissed their stale review October 23, 2026 21:07

The merge-base changed after approval.

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

Re-approving after merging main into the branch. The merge only brings in the squashed parent PR; the tree matches the one tested (web and server tests, typecheck, lint, format).

@gkhngyk
gkhngyk merged commit ed347ae into ansvisor:main Oct 23, 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

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants