Skip to content

fix(content): keep one H1 per page - #1370

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/one-h1
Oct 23, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:fix/one-h1

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

A Content Editor page now has at most one H1, its title. The user asked for this on 2026-10-22: "every article can have at most one H1, never two".

Editor

  • One place for every path in: a small Tiptap extension, _one-h1.ts (OneH1). When a change raises the page's H1 count above one, the new H1s become H2s and the H1 the page had stays. It matches that H1 by its words first, then by where it moved. This covers typing, paste, the HTML view, Add HTML and accepted agent suggestions.
  • What it leaves alone:
    • an older draft that already has two H1s, until the person changes them;
    • a version restored from History (ONE_H1_AS_IS meta), since the page on the server is that version.
  • Toolbar: Heading 1 is off while the page has an H1 elsewhere. It uses aria-disabled rather than disabled, so the reason still shows on hover: "A page has one H1, its title: use Heading 2 here".

Rules

  • New rule: "One H1 per page" (oneH1, structure group, check: 'page'). It reads "2 found" when a page has more than one H1.
  • Always on: it is fixed in RuleDef, so it has no switch, and a draft's or a saved set's on: false doesn't turn it off. The editor enforces it anyway.
  • Not for the agent: NOT_FOR_AGENT keeps it out of what the Content Agent is asked, in both Apply rules with Agent (openRulesForAgent) and Start Agent (agent-write.ts). The agent changes words and adds blocks, never a heading's level. When it is the only open rule, Apply says to make the extra H1s H2s in the toolbar.

Agent and import

  • Agent inserts: cleanInsertHtml turns an H1 into an H2, in the server's content-agent.js and the web's agent-suggestions.ts (MCP). Before, the tag was unwrapped and the H1's words were left as loose text.
  • URL import (Optimize, page-content.js):
    • Picking the title: the title's H1 is picked once, before the frame and the root go. It is the last H1 with words before the text area's first paragraph; a byline, date or breadcrumb line doesn't count as that paragraph. If there is none, the first H1 with words is used.
    • The draft's title comes from that H1. An article whose title sits in its own <header> (removed with the frame) gets it back as the H1.
    • Other H1s: they become H2s, and an H1 without words (a logo) is unwrapped.
    • Effect: a logo or site-name H1 ahead of the article no longer takes the title's place.
  • New content (paste, file or imported page): oneH1Html keeps the first H1 with words, makes the rest H2s and unwraps empty ones.

HTML blocks: H1s inside raw HTML blocks (data-html-block) aren't rewritten, but "One H1 per page" counts them. Bodies written through the API aren't rewritten either; the rule flags them in the editor.

Review fixes (5a58eac):

  • the import's title pick;
  • New content;
  • H1s in HTML blocks counted;
  • an empty H1 line never counts as the page's H1 (so Heading 1 stays on beside one, and it never stays over a worded one).

Merged main in 09a03f3; the rules import in _draft-editor.tsx is now aiTracesFound, lengthWarns, openRulesForAgent.

Related issue

User request on 2026-10-22, raised with Content Agent gap D (#1369). 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. Open a draft with an H1 and click into a paragraph. Heading 1 in the toolbar is greyed out, and hovering it explains why.
  2. On an empty line, paste HTML containing an <h1>. It arrives as an H2, and Undo removes the paste in one step.
  3. Open a draft with two H1s. The Rules tab shows "One H1 per page · 2 found" with no switch. Make one an H2 and the rule turns ✓.
  4. Optimize a URL whose page has a logo H1 before the article. The draft's H1 is the article's title.

Checked locally on the demo brand with two temporary drafts, since deleted:

  • the toolbar state and its hover reason;
  • a paste demoted to H2, and undone in one step;
  • "2 found" with no switch;
  • the light and dark themes.

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 (314 files, 2,775 tests) and yarn build;
  • server npm run format, npm run lint and npm test (172 files, 2,049 tests).

🤖 Generated with Claude Code

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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk The user asked that a page never have two H1s.

  • Editor. A small extension makes any new second H1 an H2, whether it comes from typing, paste, the HTML view, Add HTML or an agent suggestion. Heading 1 is off while the page has one.
  • Rules. A new always-on "One H1 per page" rule flags older drafts. It is never sent to the agent.
  • Agent and import. Agent inserts turn H1 into H2. URL import keeps the article's H1.

A review pass before pushing caught:

  • the import demoted the article's title when a logo or site-name H1 came first;
  • a restore from History was rewritten in the editor only;
  • the rule could be switched off while the editor still enforced it;
  • the disabled button's reason never showed on hover.

All four are fixed in adae479.

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

A few fixes before merge:

  1. URL import can still pick the wrong H1, and the draft's name is still the site name (server/src/lib/page-content.js:283, :266-268, :401-417). There are three problems:

    • titleH1 takes the first H1 inside the text area before the one just ahead of it. Take a theme that puts the title next to the content block and uses H1s for sections inside it: <article><h1>Pipeline forecasting</h1><div class="entry-meta">…</div><div class="entry-content"><p>…</p><h1>Why it matters</h1>…. This head turns the title into an H2 and makes "Why it matters" the page's H1. Main kept all of them as H1s, so the title at least stayed one.
    • heading is still body.find('h1').first(). When a logo or site-name H1 comes first, the root still widens to include that block. With the PR's own logo fixture, the logo's <a><img></a> stays above the title. With the site-branding fixture, <h2>Acme</h2> stays above it.
    • title is still the page's first H1, and Optimize › URL names the draft with it. On the site-branding fixture the draft is still called "Acme", even though its H1 is "Pipeline forecasting".

    Fix: pick the title H1 once, before the root is worked out. Take the last H1 with words that comes before the text area's first paragraph (the first p, li, pre, blockquote there of at least MIN_PARAGRAPH). If there is none, take the first H1 with words. Then:

    • use that H1 as heading, for the root and kept;
    • skip it in the H1 pass;
    • set title from its text when it is in the root.

    I tried this against this head's page-content.test.js and all 13 tests pass. In all three layouts above, the article's title comes out as the only H1 and as the draft's title, and the logo and site-name block drop out of the content. Please add the entry-title layout as a test.

  2. New content's paste and file import keep every H1 (web/src/components/content/new-content-dialog.tsx:358, bring). The body is stored as it was cleaned. The editor then loads it with no transaction, so OneH1 never runs on it. A Docs or Word paste that uses Heading 1 for its sections opens with "One H1 per page · N found", and Apply rules with Agent only says to fix each one by hand. The same paste inside the editor is fixed automatically. Fix: add one shared pass that keeps the first H1 with words, makes the others H2s and unwraps H1s without words. Apply it in bring(), so paste, file and URL all go through it.

  3. Low: H1s in HTML blocks are neither rewritten nor flagged. The description lists Add HTML as covered, and says the rule flags raw HTML blocks. It does neither: an HTML block keeps its code encoded in data-html-block, so neither OneH1 nor readPage (web/src/lib/content/rules.ts:442, :728) sees an <h1> inside it. Copy HTML and export then publish that <h1> as a second H1. Either count H1s in the decoded block code in the oneH1 check (decodeHtmlBlock, then count h1), or correct the description.

  4. Low: an empty H1 wins over a worded one (_one-h1.ts:45-54). Say the person cleared the title to retype it and then pasted an article with its H1 below. same matches the empty text, so the empty H1 stays and the pasted title becomes an H2. Heading 1 is then off in the toolbar, because the page "has" an H1. Fix:

    • in the before loop, skip H1s without words;
    • fall back to the first H1 with words (after.find((at) => newState.doc.nodeAt(at)!.textContent.trim()) ?? after[0]);
    • count only H1s with words in the toolbar's h1Taken.

Checked and fine:

  • The extension always terminates. At least one H1 is demoted each round, and the next round returns null.
  • Undo works as described. The appended demotion joins the paste's history event, so one Undo removes both.
  • Older drafts aren't touched on load. Loading one runs no transaction, so it isn't marked dirty or autosaved.
  • History restore keeps the version as it was. ONE_H1_AS_IS covers the one setContent that needs it.
  • Locked passages aren't affected. The CitedPassages lock keys on text, so a demotion never trips it.
  • The toolbar's Heading 1 can't be used while it is off. The click is dropped, and Mod-Alt-1 and # give an H2 through the extension.
  • The agent never gets oneH1. NOT_FOR_AGENT covers both Apply rules with Agent and Start Agent.
  • The new always-on rule shows up nowhere else. Nothing else lists or saves rules, and the met count isn't stored.
  • The two cleanInsertHtml changes agree. They give the same output, and #1369's splitReplace still takes an H1 replace's words from the H2 it now becomes.

Merge state: this branch merges cleanly on main and with #1369. After #1366 lands it needs main merged in: there is one conflict in _draft-editor.tsx, the rules import line, and the fix is trivial (import { aiTracesFound, lengthWarns, openRulesForAgent } from '@/lib/content/rules';). The toolbar, rules.ts and the tests merge on their own.

cihan-gyk and others added 2 commits October 22, 2026 23:44
# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
…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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed in 5a58eac, on top of a main merge (09a03f3, the rules import conflict resolved as you wrote):

  1. page-content.js. The title's H1 is picked once, before the frame and the root: the last H1 with words before the text area's first paragraph (p/li/pre/blockquote ≥ MIN_PARAGRAPH), else the first with words. It is used as heading, skipped in the H1 pass, and title comes from it.
    • A byline/meta/breadcrumb line above the title doesn't count as that first paragraph.
    • Tests: your entry-title layout (title H1 a direct child of <article>, a section H1 in entry-content → H2), a title inside the article's own <header>, and a site-branding H1 + entry-meta line before the title.
  2. New content. One shared pass in bring(): oneH1Html (first worded H1 stays, others → H2, empty H1s unwrapped) for paste, file and imported page. Tested.
  3. HTML blocks. readPage counts worded H1s inside HTML blocks (decodeHtmlBlock), so "One H1 per page" flags them. They aren't rewritten; the PR body says so now.
  4. Empty H1s. h1Positions counts only H1s with words, so an empty H1 never wins over a worded one and h1Taken ignores it.
    • Side effect: # or Mod-Alt-1 on an empty line still shows an H1 until the first keystroke, and only then becomes an H2 (if the page has a title). It is not demoted straight away as in your recipe; say if you'd rather it were.

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

Approving, with two small follow-ups below. They only show on uncommon layouts, so a separate PR is fine, since #1371 and the rest of the stack depend on this one. The four earlier items are done in 5a58eac3:

  1. URL import's title H1. I ran the three layouts from the last review against page-content.js at this head:
    • Entry title next to an entry-content with a section H1. "Pipeline forecasting" is the only H1 and the draft's title, and "Why it matters" is an H2.
    • A logo H1 first. The logo's link and image drop out. The article's H1 is the only H1, and it is now the draft's title (the title was empty before).
    • A site-name H1 first. The article's H1 is the only H1 and the draft's title, not "Acme". In the PR's fixture the site name sits inside <main>, which is the root, so it stays in the content as an H2. Without <main> it drops out.
    • A title in the article's own <header> comes back as the H1, and all 16 tests pass.
  2. New content. bring() runs oneH1Html on the cleaned HTML from all three paths, paste, file and URL (new-content-dialog.tsx:365).
  3. HTML blocks. readPage counts the H1s with words inside HTML blocks (rules.ts:464, :745), and the PR body now says they are flagged, not rewritten.
  4. Empty H1s. h1Positions counts only H1s with words (_one-h1.ts:24). An empty H1 never wins over a worded one, and h1Taken ignores it. The side effect you describe, where a # line is an H1 until its first keystroke, is fine as it is.

Follow-ups:

  1. A plain dated line above the title still counts as the text's first paragraph (server/src/lib/page-content.js:293-304).

    • The comment and the PR body say a byline or date line doesn't count. In fact only blocks with furniture names (meta, byline, breadcrumb) are skipped.
    • Take <div class="site-branding"><h1>Acme</h1></div><article><p class="date">Published on October 22, 2026 by Ada Lovelace</p><h1>Pipeline forecasting</h1><p>…. The content now starts with <h1>Acme</h1>, then the date line, then <h2>Pipeline forecasting</h2>, and the draft is called "Acme". Main kept the article's H1 as an H1 there.
    • Fix: skip byline lines too, as judge does:
      .find((el) => {
        const text = clean($(el).text());
        return (
          text.length >= MIN_PARAGRAPH &&
          !(text.length <= MAX_BYLINE && BYLINE.test(text)) &&
          ![el, ...$(el).parentsUntil(textArea).toArray()].some((block) =>
            named($(block), PAGE_FURNITURE_WORDS),
          )
        );
      })
  2. On a page with no paragraphs to go by, the site header's H1 takes over (page-content.js:305-306).

    • worded is collected before the frame is removed. With no lead, the fallback worded[0] can be an H1 in the site's <header>.
    • Take <header class="site"><h1>Acme</h1></header><main><h1>Pricing</h1><div>Starter</div><div>Pro</div></main>. "Pricing" becomes an H2, the content is headed with <h1>Acme</h1>, and the draft is called "Acme". Main kept "Pricing" as the H1.
    • Fix: in the fallback, take the first H1 with words that is still on the page before one the frame took:
      const titleH1 =
        (lead && worded.filter((el) => order.get(el) < order.get(lead)).at(-1)) ||
        worded.find((el) => $(el).closest('body').length > 0) ||
        worded[0] ||
        null;
    • I tried both fixes on a copy. All 16 tests still pass, and every layout above, plus these two, comes out with the page's own H1 as the only H1 and as the draft's title. Please add both pages as tests.

Known limit, no change needed now: when the text opens with a section H1 before its first paragraph (<article><h1>Title</h1><div class="entry-content"><h1>Why it matters</h1><p>…), that section H1 is picked as the title. It only happens on pages that use H1s for sections and open with one.

Merge notes

  • 09a03f3a has no hidden changes. Re-merging its parents gives the same tree, apart from the _draft-editor.tsx conflict. That is resolved as import { aiTracesFound, lengthWarns, openRulesForAgent } from '@/lib/content/rules';, and both new names are used. The toolbar, rules.ts, its tests and en.json merged on their own.
  • It merges cleanly on current main (5b679380) and with #1369. It contains no other open PR and adds no migration.

@gkhngyk
gkhngyk merged commit fa8ce77 into ansvisor:main Oct 23, 2026
5 checks passed
gkhngyk added a commit that referenced this pull request Oct 23, 2026
…e draft's sources (#1371)

* fix(content): keep agent answers out of headings

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]>

* fix(content): keep one H1 per page

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]>

* fix(content): split a heading's answer off whatever follows it, and only a real answer

Review fixes for #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]>

* fix(content): pick an import's title H1 once, keep one H1 in New content, count HTML blocks'

Review fixes for #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]>

* feat(content): let the Content Agent link to the brand's pages and the 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]>

* test(content): read splitReplace's links beside the heading split's results

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 23, 2026
… the draft's sources (#1372)

* fix(content): keep agent answers out of headings

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]>

* fix(content): keep one H1 per page

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]>

* fix(content): split a heading's answer off whatever follows it, and only a real answer

Review fixes for #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]>

* fix(content): pick an import's title H1 once, keep one H1 in New content, count HTML blocks'

Review fixes for #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]>

* feat(content): let the Content Agent link to the brand's pages and the 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]>

* test(content): read splitReplace's links beside the heading split's results

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

* feat(content): let agents link over the API, to the brand's pages and 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]>

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 23, 2026
…1374)

* fix(content): keep agent answers out of headings

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]>

* fix(content): keep one H1 per page

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]>

* fix(content): split a heading's answer off whatever follows it, and only a real answer

Review fixes for #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]>

* fix(content): pick an import's title H1 once, keep one H1 in New content, count HTML blocks'

Review fixes for #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]>

* feat(content): let the Content Agent link to the brand's pages and the 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]>

* test(content): read splitReplace's links beside the heading split's results

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

* feat(content): let agents link over the API, to the brand's pages and 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]>

* feat(content): start a page brought in with the prompts it answers

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]>

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 23, 2026
…1383)

* fix(content): keep agent answers out of headings

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]>

* fix(content): keep one H1 per page

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]>

* fix(content): split a heading's answer off whatever follows it, and only a real answer

Review fixes for #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]>

* fix(content): pick an import's title H1 once, keep one H1 in New content, count HTML blocks'

Review fixes for #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]>

* feat(content): let the Content Agent link to the brand's pages and the 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]>

* test(content): read splitReplace's links beside the heading split's results

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

* feat(content): let agents link over the API, to the brand's pages and 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]>

* feat(content): start a page brought in with the prompts it answers

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]>

* feat(content): aim an optimized page's Length rule at its own length

A page brought in to optimize (pasted, imported from its URL or a file,
read by Start or by an Action Center task) stores its text length as
rules.importLength. Its Length rule aims there (±20%), not at a new
page's target for the type, and the Content Agent gets the same aim.
My rules still apply to such a draft, but not their Length value; Save
as my rules keeps the workspace's value, and the person's own value
wins.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 23, 2026
…th can't fit the rules (#1384)

* fix(content): keep agent answers out of headings

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]>

* fix(content): keep one H1 per page

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]>

* fix(content): split a heading's answer off whatever follows it, and only a real answer

Review fixes for #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]>

* fix(content): pick an import's title H1 once, keep one H1 in New content, count HTML blocks'

Review fixes for #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]>

* feat(content): let the Content Agent link to the brand's pages and the 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]>

* test(content): read splitReplace's links beside the heading split's results

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

* feat(content): let agents link over the API, to the brand's pages and 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]>

* feat(content): start a page brought in with the prompts it answers

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]>

* feat(content): aim an optimized page's Length rule at its own length

A page brought in to optimize (pasted, imported from its URL or a file,
read by Start or by an Action Center task) stores its text length as
rules.importLength. Its Length rule aims there (±20%), not at a new
page's target for the type, and the Content Agent gets the same aim.
My rules still apply to such a draft, but not their Length value; Save
as my rules keeps the workspace's value, and the person's own value
wins.

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

* feat(content): say when an agent run stops at its most, and when Length can't fit the rules

A run of Apply rules with Agent leaves at most 8 changes (the API's cap,
mirrored as AGENT_RUN_MAX). A full batch now says so in its toast and,
once decided with rules still open, in the agent bar: run it again for
the rest.

The Rules tab warns under Length when the fan-out H2s, FAQ questions and
summary the rules still ask for take more text, at their least, than
Length allows (+20%), so the person can raise Length or ask for fewer.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 23, 2026
* fix(content): keep agent answers out of headings

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]>

* fix(content): keep one H1 per page

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]>

* fix(content): split a heading's answer off whatever follows it, and only a real answer

Review fixes for #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]>

* fix(content): pick an import's title H1 once, keep one H1 in New content, count HTML blocks'

Review fixes for #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]>

* feat(content): let the Content Agent link to the brand's pages and the 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]>

* test(content): read splitReplace's links beside the heading split's results

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

* feat(content): let agents link over the API, to the brand's pages and 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]>

* feat(content): tell the Content Agent which fan-outs to use

The fan-out rules stayed open after a run: the agent was told only "now: 3
of 4", wrote H2s and FAQ questions of its own, and the check didn't count
them. A fan-out rule's status now names what's missing (fanoutH2: the top
fan-outs no H2 carries; fanoutFaq: the most searched ones no FAQ question
uses, or the top ones while there's no FAQ), and both Apply rules with
Agent and Start Agent send them in the rule's detail, quoted, within the
room the server allows. Both prompts share FANOUT_RULE: an H2 or a FAQ
question per named fan-out, in its words, and a change is called a fan-out
answer only when it uses one listed.

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

* fix(content): keep FAQ fan-outs to one question per heading

The Content Agent appended a fan-out's question to an existing FAQ
question heading ("What is AEO? What is an AEO tracker?"), which the
editor's heading guard then refused. The fan-out rule now says to insert
a new question with its answer after an existing answer, or reword a
question only when its answer still answers it. A heading replace that
makes a heading ask more than one question is dropped, on the server and
over the API (heading_two_questions), and a second question is no longer
moved under the heading as its answer.

Review fixes: the new-page prompt names the fan-out rule too, and
fanoutFaq counts the different fan-outs its questions use, asking for no
more than there are, so it never stays open with nothing to name.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
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