Skip to content

feat(content): set the site type from the editor and tell the Content Agent (CE-056) - #1449

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

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-business-type

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

First PR of the Quality spec's Phase 2. CE-056: "Business type (B2B / B2C / E-commerce) in project settings, guessed at onboarding, switch in the editor."

The brand already has it as brands.site_type (00205): the Site type select in Brand settings, guessed from the industry and Shopping mode until someone picks one (siteTypeOf). So this PR adds the two missing pieces. I kept the app's own name, "Site type", in the UI and in the prompt line, as Brand settings and the opportunity generator use it.

  • Switch in the editor (web, only once NEXT_PUBLIC_CONTENT_QUALITY_PHASE is 2):
    • Admins and managers get a "Site type · for the whole brand" group at the top of the page type menu. Brands' update policy is admin/manager, as in Brand settings.
    • Picking one saves it with the existing updateBrand action and updates the brand store, so the Library, Plan and Prompts follow it too. Only then does the editor take it:
      • the page types offered follow it;
      • My rules (kept per site type since 00227) are read again, and count as unread until they are in;
      • the Rules tab follows it.
    • A detected page type is saved again, so the server re-detects it for the new site type, and the Library and the agent agree with the header.
    • One pick at a time. A failed save keeps the old type and says so.
    • While no site type is picked, the group says it's guessed.
  • The Content Agent is told (server, only once the new CONTENT_QUALITY_PHASE is 2):
    • The fix, write and brief prompts get a line after the industry, e.g. Site type: E-commerce (an online shop selling products).
    • server/src/lib/content-quality.js mirrors the web's qualityPhase(). The later Phase 2 PRs need it too (the auto hand-off, the brand facts sweep).
    • Both .env.example files say to set the two together.

"Guessed at onboarding": onboarding saves the industry and Shopping mode, and the site type is guessed from them when it's read, as Brand settings shows it. That gives the same result without writing a guess, so I left onboarding as it is.

Phase 2 plan (one PR each, in this order):

  1. CE-056 (this PR)
  2. CE-046 source classes (rules first, then the AI fallback)
  3. CE-048 Your input
  4. A no-fabrication test set
  5. CE-045 claims in the person's own text
  6. CE-047 brand facts
  7. CE-049 visual proof spots
  8. CE-050 disclosure / balance / answer-first
  9. CE-051 hand off

Related issue

Quality spec (Drive), Phase 2, 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. Set NEXT_PUBLIC_CONTENT_QUALITY_PHASE=2 in web/.env.local and CONTENT_QUALITY_PHASE=2 in server/.env, then restart both.
  2. As an admin, open a draft and click its page type tag. The menu starts with "Site type · for the whole brand": B2B SaaS / E-commerce / B2C, with "Guessed until someone picks one." when the brand has none.
  3. Pick E-commerce. The toast says "Site type set to E-commerce for the whole brand.", the menu now offers Product page, Category page…, and Brand settings › Site type shows E-commerce.
  4. Run Agent on the draft. The server's prompt includes Site type: E-commerce (an online shop selling products) after the industry.
  5. As an analyst, or with the flag at 1, the menu has no site type group.

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

Server: format, lint and 2,329 tests pass. Web: 3,343 tests and the build pass.

I haven't checked this in the browser yet; it goes into the next local test session, with screenshots.

🤖 Generated with Claude Code

… Agent (CE-056)

Quality phase 2's business type is the brand's site type (00205), set in
Brand settings and guessed until someone does.

- the page type menu offers it to admins and managers once
  NEXT_PUBLIC_CONTENT_QUALITY_PHASE is 2, for the whole brand; the page
  types offered, My rules (read again once saved) and the Rules tab follow
  it, and a detected page type is saved again for the new site type
- the fix, write and brief prompts get a "Site type:" line after the
  industry once the server's CONTENT_QUALITY_PHASE is 2 (new
  content-quality.js qualityPhase())

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep ansvisor#1438's useUserRole import and canManage declaration; drop this branch's duplicates.

@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, fine after merge.

Checked:

  • Server flag unset. qualityPhase() is 0 and siteTypeLine() returns '', so the fix, write and brief prompts are the same as on main. The only other server change is site_type, shopping_mode_enabled added to the three brand selects, and both columns exist. No other server code reads CONTENT_QUALITY_PHASE. The people guard and the link checks have no phase gate, and the web's phase-1 Quality (trust, readability, the Quality tab, authors) stays on qualityPhase() >= 1. So nothing turns off while the server flag is unset, and the two flags can go live in either order.
  • Who can save. The site type group shows only for canManage, which matches brands' admin/manager update policy. updateBrand writes through the user's client, so RLS enforces it, and a refused save throws and shows siteFailed.
  • What follows a pick. getMyRuleSets and saveMyRuleSet read the site type from the database, so the re-read after the save gets the new type's sets. saveContentDraft re-detects a detected page type against the brand's current site type, and autosave doesn't skip an unchanged page, so the extra save re-detects it as intended. The update handler reads siteTypeRef, so detection while someone types uses the new type too. All callers of PageTypeMenu, EditorSidePanel and useDraftRules are updated.
  1. (low) _draft-editor.tsx:1892: you can't confirm a guessed site type from the editor. While the brand has none picked, the menu says "Guessed until someone picks one." (_page-type-menu.tsx:107), and the guessed type is already the selected radio. Clicking it reaches pickSite (Base UI's radio group calls onValueChange even when the value doesn't change), but next === siteType returns early, so nothing is saved and the note stays. Fix: when siteGuessed, let the current value through and save it with updateBrand, then skip the re-detect and the autosave, since the type doesn't change. Otherwise, reword the note to point to the other types.

Merge note: #1438 also adds import { useUserRole } from '@/hooks/use-user-role' and const { canManage } = useUserRole(); to _draft-editor.tsx. Git merges the two without a textual conflict, but the combined file has a duplicate import and a second canManage declaration, so typecheck fails and the editor's page test doesn't load. The merge of main on this branch (c0f448e) keeps #1438's import and declaration and drops this PR's. All of this PR's canManage uses come after #1438's declaration. It also keeps both imports where they touched (SendDialog and updateBrand).

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