Skip to content

feat(content): start a page brought in with the prompts it answers - #1374

Merged
gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/optimize-draft-prompts
Oct 23, 2026
Merged

gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/optimize-draft-prompts

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

A page brought in to optimize now starts with the brand's prompts it answers, so it has fan-outs, and a page without them points to where they come from.

Stacked on #1372 (A2; a sibling of the fan-out PR). This PR's own change is 9d61114. It can merge in either order with the fan-out PR.

On prod, an Optimize draft imported from a URL showed "No fan-outs" for both fan-out rules, so they silently dropped out (11 rules instead of 13).

  • Cause: a page brought in by paste, URL or file was created with prompt_ids: [].
  • Where fan-outs come from: the content_draft_sources RPC reads them from the draft's prompts, plus prompts whose answers cited that very page in the last 30 days. Most imported pages had neither.

Matching (web/src/lib/content/page-prompts.ts, new)

  • matchPagePrompts(title, html, prompts) reads the title and H1–H3 headings (server-side, with a regex: the action has no DOMParser) as wordsOf words.
  • It keeps the brand's prompts with at least 60% of their words, and at least 2 of them, in those headings. The most words in common first (a short, broad prompt matches too easily), up to 10.
  • createContentDraft does this for a content source: it reads the brand's newest 1,000 active prompts and matches them against the sanitized body.
  • If that read fails, the page still starts with no prompts, as before.
  • The person can leave any matched prompt out in Sources.

Rules tab. A fan-out rule shows Add prompts instead of "No fan-outs" only when the sources were read and the draft has no prompts at all. A draft whose prompts' answers ran no searches (e.g. AI Overviews, Gemini) keeps "No fan-outs". It is a button that opens the Sources tab, and its hover hint says the fan-outs come from the page's prompts.

No migration.

Related issue

Content Agent rule gaps, item E (folded into B), found by testing on prod on 2026-10-22. No issue.

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. New content → Optimize content: paste a page (or import its URL) whose headings match some of the brand's tracked prompts.
    • The draft's Sources list those prompts and their fan-outs.
    • The fan-out rules show a status ("0 of 4"…), not "No fan-outs".
  2. Open a draft with no prompts and no fan-outs. The fan-out rules show Add prompts; clicking it opens the Sources tab.

Tests:

  • page-prompts.test.ts: the match, a single shared word, the cap, and headings only;
  • content-drafts-start.test.ts: an imported page starts with its matched prompts;
  • the editor's page.test.tsx: Add prompts opens Sources.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) (0 errors; the 6 warnings are in untouched files, as on main)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • web yarn test (2,860 tests) and yarn build.

🤖 Generated with Claude Code

cihan-gyk and others added 12 commits October 22, 2026 22:42
A replace on a heading that carried its answer ("What is X? X is …") or a
whole FAQ was flattened into the heading's line. Content Agent and the
editor API now split such a replace: the heading keeps its words and the
answer or blocks become an insert after it, kept together or not at all.
An agent change may not grow an H1 past 70 characters or another heading
past 90 (a long imported heading may still be shortened); both agent
prompts and the MCP description say a heading stays one line, and the
editor won't accept an older suggestion that would glue text into one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A page's H1 is its title. The editor now makes a second H1 an H2 however it
comes (typed, pasted, the HTML view, Add HTML or an agent suggestion),
keeping the page's own; Heading 1 is off while the page has one, and says
why on hover. A version restored from History and older drafts keep theirs,
and a new always-on "One H1 per page" rule flags them. The Content Agent is
never asked to fix it (it doesn't change heading levels) and its inserted
H1s become H2s. URL import keeps the H1 nearest the article's text, not a
logo's or a site name's, and makes the rest H2s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
…nly a real answer

Review fixes for ansvisor#1369 (gkhngyk):
- the question/answer split runs whenever the passage is a heading, also
  when blocks follow, and the answer goes first under it (inline answer
  plus a list, or <h2>Q? A.</h2><p>…);
- a heading that fits keeps a subtitle: only an answer that ends a
  sentence (. ! 。 !) is split off; past the limit the rest always goes;
- "?" ends a question only before a space; a full-width "?" with or
  without one;
- the regex has no catastrophic case on long text, and the garbled doc
  comment in agent-suggestions.ts reads again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ent, count HTML blocks'

Review fixes for ansvisor#1370 (gkhngyk):
- URL import picks the title's H1 once, before the frame and the root go:
  the last H1 with words before the text's first paragraph (a byline,
  date or breadcrumb line doesn't count as one), else the first; the
  title comes from it, and the root's other H1s become H2s;
- New content keeps one H1 in a pasted page, a file or an imported page
  (oneH1Html in bring(): the first H1 with words stays, others are H2s,
  empty ones unwrapped);
- "One H1 per page" counts H1s with words inside HTML blocks too;
- an empty H1 line never counts as the page's H1 in the editor, so it
  never stays over one with words, and Heading 1 stays on beside it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e draft's sources

The agent could never meet the Internal links, Outbound links or Cite
sources inline rules: a replace's new words were plain text, inserts took
no <a>, and it had nowhere to link to. When one of those rules is asked
for, it now gets the brand's own pages (site_pages, the most cited and
visited first) and the draft's sources (cited pages, not the brand's or a
competitor's, not left out), and may link only to those URLs: any other
link is unwrapped, tracking parameters come off. A replace keeps its links
beside its words (after_links, 00240); an insert keeps them in its HTML.
The editor puts them on as link marks when a suggestion is accepted, takes
them off on undo, and shows on the card where each one goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	server/src/lib/content-agent.js
… the draft's sources

The editor API's suggest_content_changes took no links, so an agent working
through MCP could not meet the link rules either. get_content_draft now
lists link_targets (the brand's own pages, and the draft's sources without
the brand's or a competitor's), and suggest_content_changes keeps a link
only to one of those URLs, as the Content Agent does on the server: a
replace's links go in after_links, an insert's stay in its HTML, any other
link is unwrapped and a link with no words dropped. The targets are read
only when a suggestion links.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An Optimize draft pasted, read from its URL or a file started with no
prompts, so it had no fan-outs unless AI answers cited that very page, and
the fan-out rules read "No fan-outs". It now starts with up to ten of the
brand's active prompts its title and headings speak to (60% of a prompt's
words and at least two, the most in common first), which the person can
leave out in Sources. A draft with no prompts shows "Add prompts" on those
rules, opening the Sources tab.

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 22, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Content Agent rule gaps E (stacked on #1372, a sibling of #1373): an Optimize page brought in by paste, URL or file now starts with up to 10 of the brand's prompts its headings match, so it has fan-outs; a draft with no prompts gets an Add prompts link to Sources. A review pass before pushing narrowed that link to drafts with no prompts (not ones whose engines ran no searches), and ranked matches by words in common. Two possible follow-ups it noted: Action Center's Optimize page and MCP createContentDraftFor could match prompts the same way.

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

Checked:

  • The prompts read (web/src/lib/actions/content-drafts.ts:508-524).
    • It uses the member's own client, after getUser, and goes through the prompts RLS. It is filtered to prompt_sets.brand_id = brandId and active prompts, with at most 1,000 rows. That is the same shape as the topic and prompt sources next to it.
    • A failed read logs the error and starts the draft with no prompts, as before. The overlap check passes no page, so it reads nothing.
  • Matching (web/src/lib/content/page-prompts.ts). It reads only the title and H1–H3 headings of the sanitized body. wordsOf drops stop words and short words, so the 2-word / 60% floor holds, and more words in common rank first. The cap of 10 is far under MAX_DRAFT_PROMPTS.
  • Add prompts.
    • It shows only once the sources are read without failing and the draft has no prompts at all. A draft whose prompts ran no searches keeps "No fan-outs".
    • Sources' Add source dialog does add a prompt, so the hint leads somewhere.
    • Both strings are in en.json, and the button uses text-primary.
  • Cost. There is no LLM call. An imported page now brings up to 10 prompts and their fan-outs into the agent's request, which is small.
  • Tests. Matching, the cap, headings only, the insert's prompt_ids, and Add prompts opening Sources.

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

@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 23, 2026
@gkhngyk
gkhngyk merged commit b0aec6f 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants