Skip to content

feat(content): read what kind of source each link is, and underline the weak ones (CE-046, part a) - #1450

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-source-classes
Oct 24, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-source-classes

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

This is Quality Phase 2, CE-046 "Source classification (primary / weak / competitor / own)", part a: rules only, no AI. Part b will add an AI read for addresses the rules can't place, cached per host. Everything here sits behind NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2; with the flag at 1, nothing changes.

  • sourceClass() (web/src/lib/content/source-class.ts) reads a link's kind from its address. It uses the citations' categories (classifyDomain) and a short research/standards list:

    • primary: government, education and international bodies; journals and preprints (doi.org, arxiv.org, nature.com…); standards bodies (w3.org, ietf.org, iso.org…);
    • secondary: news and magazines, review sites, and Wikipedia (anyone edits it);
    • weak: forums, social posts, and uploaded papers (academia.edu);
    • competitor: a competitor's page. On a comparison, alternatives or best-of page, it is primary instead (spec §11: a competitor's own page is where its facts come from);
    • own: the brand's pages, which aren't sources;
    • null: an address the rules can't place. It is left out, so it neither raises nor lowers Trust. No fake points.
  • Trust gets two checks from spec §2.2:

    • primarySources (15): a primary source among the placed ones;
    • noWeakSources (10): the share of placed sources that aren't weak or a competitor's, unless the person kept them.

    Two placed sources score Trust on their own, even without a figure or a dated source. That is a judgement call: Phase 1 waits for a figure or a dated source because one link would set the whole score, so here it takes two. Say if you'd rather wait for a figure too.

  • Quality suggests replacing weak sources: "2 sources are weak: a forum, a social post or a competitor's page", with Show and Keep on the first one. It also suggests "No primary source yet". Both appear only once Trust is scored, so their gain is never made up. Before you publish's warning reads them as reasons, e.g. "Trust 40, below 60. No primary source yet. …".

  • In the draft, a weak source gets an amber wavy underline in place of its link's own, with why on hover. It is a ProseMirror decoration, so no save, export, copy or CMS push carries it. It is marked again on every change of the page while any is listed: a restore, an accepted suggestion, or a second link to the same address.

  • Keep saves the address on the draft: 00263 adds content_drafts.kept_sources text[] (≤ 50) and the security-invoker content_draft_keep_source(uuid, text).

    • Members' update policy covers it, and the server-columns guard doesn't touch it.
    • The updated_at bump goes through autosave's same-body retry, as the author pick does.
    • At 50, it says so.
  • Show on a link listed twice now goes to where the page has it first: byUrl keeps the first entry. Stale and broken links get the same fix, which matches what their comment always said.

"Own data as a primary source" comes with CE-048 (Your input), so the copy doesn't promise it yet.

Related issue

Quality spec (Drive), Phase 2, CE-046 (part a). Follows #1449 (CE-056).

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. Apply 00263 and set NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2 in web/.env.local.
  2. In a draft, add a paragraph linking https://www.reddit.com/r/coffee and another linking https://www.who.int/. The Reddit link gets an amber wavy underline; hover it to read why.
  3. Open Instructions › Quality. Trust is scored, with "1 source is weak: …" (Show, Keep). Show scrolls to the link.
  4. Click Keep. The underline goes, the suggestion goes, and reloading keeps it that way.
  5. Remove the WHO link and add a news link instead. "No primary source yet" appears.
  6. With the flag at 1, none of this shows.

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

00263 is applied on the dev DB and schema.sql is rebuilt. Web: all 3,365 tests and the build pass. I checked that the build's CSS has the rule removing the link's own underline under a weak source. I haven't checked it in the browser in both themes yet; it goes into the next local test session, with screenshots.

🤖 Generated with Claude Code

…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]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 24, 2026
Rebuild supabase/schema.sql with 00262 and 00263, and keep both RPCs in web/src/types/supabase.ts.

@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. One small follow-up:

  1. A weak source is underlined before Quality offers Keep for it. _draft-editor.tsx:557 underlines every link in trust.weak, but trustSuggestions only lists the weak sources once Trust is scored (_quality-tab.tsx:435). Take a page whose only source is one forum thread and that has no figures: the link gets the amber underline, and its hover says "See Quality to replace or keep it", but Quality has no row for it. Either underline only while trustScore.score !== null, or list the weak row with Keep and no gain before Trust is scored, the way broken links are listed.

Merge notes:

  • With #1437 on main, the merge of main on this branch rebuilds supabase/schema.sql with build-schema.sh and keeps both RPCs in web/src/types/supabase.ts.
  • getContentDraft now selects kept_sources, so 00263 has to be on prod before this merges. Otherwise the editor fails to load.
  • 00263 dry-runs cleanly on prod on top of 00262. content_draft_keep_source keeps the address for a member and returns nothing for a member of another workspace. The server-columns guard lets the member's write through.

@gkhngyk
gkhngyk merged commit a79e4af 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

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