Repository navigation
feat(content): tell the Content Agent which fan-outs to use - #1373
Conversation
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
…esults Co-Authored-By: Claude Opus 5.5 <[email protected]>
… 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]>
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]>
|
@gkhngyk Content Agent rule gaps B (stacked on #1372): the fan-out rules now name the missing fan-outs, so the agent writes those, in their words, instead of questions of its own. This covers both Apply rules with Agent and Start Agent. A review pass before pushing caught that a page with no FAQ yet got no names at all, and that Start Agent read a page it was about to rewrite; both are fixed. |
gkhngyk
left a comment
There was a problem hiding this comment.
One fix before merge:
-
A new page's prompt doesn't get the fan-out rule (
server/src/lib/content-writer.js:94-103).FANOUT_RULEis added toSUGGEST_SYSTEM_PROMPT(line 113) and the fix-rules prompt. It is not inWRITE_SYSTEM_PROMPT, whichrunDraftWritinguses formethod === 'create'.- That is the case where
agentWriteRequestnames every top fan-out ("a page the agent writes anew starts from none"). So on Create and Try again, the model sees the names in the rule detail but not the instruction to use their words in an H2 or an FAQ question, rather than questions of its own. - Fix: add a line shaped for the page schema to
WRITE_SYSTEM_PROMPT. For example: "For each fan-out a rule names, use its words: a section heading for fanoutH2, an FAQ question ending in "?" for fanoutFaq." Assert it in the create-path test incontent-writer.test.js.
-
Low:
fanoutFaqcan stay open with nothing to name (web/src/lib/content/rules.ts:768-773).missinglists the fan-outs no question uses yet. With fewer fan-outs than the rule asks for (2 fan-outs, the default 3 questions), both get used,missingbecomes[], and the rule stays at "2 of 3".- The agent then gets no names. Any question it writes on its own doesn't count.
- Fix: when
missingis empty butused < n, name the top fan-outs again (a question may reuse one). Or capofat the fan-outs there are, asfanoutH2does.
Checked and fine:
- Budget.
fanoutsToUsekeeps the joined list within 300 characters, separators included. Withaimandnowin front, the Apply rules detail stays well under the server'sdetail.max(500). - Status shapes.
fanoutH2gives the same count and total as before, plusmissing.needsFaqonly gains an optional field.fanoutsToUsereturns null for every other status. Nothing reads statuses by deep equality. - Start Agent request. It reads the same included fan-out rows as the editor's rule context (
buildSourceGroups, included only). It uses the existing page only foroptimize, and only the two fan-out rules get a status. - Cost. There are no new calls. The two system prompts grow by about 90 tokens, and each fan-out rule's detail by at most 300 characters.
- i18n and tests.
agent.fanoutsis inen.json. The tests cover the lists, the budget, new vs existing page, the detail sent, and both server prompts.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
|
@gkhngyk Thanks. Both fixes are in a7c015b, on top of a merge of main (b2ec760; #1369–#1372 are squashed in, so the diff is this PR's own again).
Also in this commit, from the user's test on prod (draft 3b94abb0, "2 suggestions couldn't be applied"):
Known and left as it was: an insert can still carry a heading with two questions ( Checks: server 2,096 and web 2,899 tests, lint, typecheck, format and build all pass. The PR body is updated. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. Both earlier items are fixed, and the one-question guard is right. One optional follow-up:
- Low, optional:
fanoutFaqstill says "questions" (web/src/lib/content/rules.ts:86).- The rule now counts the different fan-outs its questions use (
rules.ts:845-852). Two questions on one fan-out count once, and one question on two counts both. - Its unit is still
questions, so the Rules tab can show "1 of 3" next to "3 questions" on a page with three fan-out questions. - Fix: give it
unit: 'fanouts', asfanoutH2has.
- The rule now counts the different fan-outs its questions use (
Earlier items:
- New-page prompt: done.
WRITE_SYSTEM_PROMPTnames the fan-out rule for its own schema (server/src/lib/content-writer.js:101). The create-path test asserts it. fanoutFaqopen with nothing to name: done.ofismin(N, fan-outs)andusedcounts different fan-outs, somissingis never empty while the rule is open.lengthConflictcaps it the same way. The tests cover fewer fan-outs than N, two questions on one fan-out, and one question on two.
Checked and fine in a7c015b:
asksMoreThanOne(content-agent.js:269,suggestions.ts). It only drops a heading replace that adds a question, so a heading that already asked two can still change. It runs aftersplitReplace, so it reads the words that would go in. The server (keepSuggestions) and the API (keepAgentSuggestions,heading_two_questions) behave the same. The MCP tool description lists the new reason, and nothing else lists the dropped reasons.splitReplace(content-agent.js:321,agent-suggestions.ts:201). A second question is no longer moved under the heading as its answer. That suggestion is now dropped as a whole, so no paragraph ends up under the wrong question. An answer that ends on a question is still split off. The server and web copies match.FANOUT_RULE(content-agent.js:50). The insert it asks for (an H3 and a paragraph after the last answer paragraph) is whatfaqQuestionscounts. The tags it uses are allowed in inserts.- Merge of main (b2ec760): no hidden changes. The PR's diff against main is the same as a667fc6's own diff. The only difference is context in
page.test.tsx, where #1384's "a full batch is the most one run makes" test and this PR's fan-out test both stay. - It merges cleanly on main (c456881). There's no migration.
gkhngyk
left a comment
There was a problem hiding this comment.
Re-approving after merging main (#1387) into the branch. server/src/lib/content-writer.test.js conflicted in the new-page test: I kept both sides, #1387's budget charge/release assertions and this PR's fan-out prompt assertion. The PR's diff against main is otherwise unchanged. The merged tree passes the web and server tests, typecheck, lint and format.
Summary
The fan-out rules now tell the Content Agent which fan-outs to use, so it can meet them.
On prod, "Use top fan-outs as H2s" and "Use fan-outs in FAQ questions" stayed open after every agent run.
carries, 75% of a fan-out's words) didn't count them.fanoutFaq, the agent appended the fan-out's question to an existing FAQ question heading ("What is AEO? What is an AEO tracker?"). The editor's heading guard then refused it ("2 suggestions couldn't be applied").Rules (
web/src/lib/content/rules.ts)fanoutH2gives the top-N fan-outs that no H2 carries;fanoutFaqgives the most searched fan-outs that no FAQ question uses, as many as are still needed. On a page with no FAQ yet (needsFaq), it gives the top N.fanoutFaqcounts the different fan-outs its questions use, asfanoutH2counts its H2s, and asks for no more than there are (of= min(N, fan-outs)). Before, with fewer fan-outs than N it could stay open with nothing left to name. Two questions using the same fan-out now count once.lengthConflictcounts the same.fanoutsToUse(status)quotes them for the agent: most searched first, within 300 characters. A fan-out too long for the room left is skipped, so a shorter one after it still fits.Where the agent gets them
fan-outs to use, in their words: "…"; "…". That fits the server's 500-character detail.agentWriteRequestchecksfanoutH2andfanoutFaqagainst the page and passes their status to the rule describer, which names the fan-outs the same way.Prompts (server).
FANOUT_RULEis shared by the fix-rules and Start Agent (optimize) prompts:fanoutH2) or a question ending in "?" under the FAQ heading (fanoutFaq), not questions of its own;WRITE_SYSTEM_PROMPT(a new page, Create and Try again) gets the same instruction, shaped for its schema: a section heading forfanoutH2, an FAQ question forfanoutFaq.One question per heading, enforced.
asksMoreThanOnedrops a heading replace that makes the heading ask more than one question. It applies on the server (keepSuggestions) and over the API (keepAgentSuggestions, dropped reasonheading_two_questions, listed in the MCP tool description). A heading that already asked two can still change.splitReplaceno longer moves a second question under the heading as if it were the answer, with or without its own answer after it. An answer that ends on a question is still moved.No migration. The MCP path doesn't send rule statuses; it gets the one-question guard only.
Related issue
Content Agent rule gaps, item B, found by testing on prod on 2026-10-22. No issue.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
fanoutH2/fanoutFaqdetails name the missing fan-outs. The agent's H2s and FAQ questions use their words, and the rules move.There are no AI keys locally, so this was checked through the request the editor builds and the prompts:
rules.test.ts: the missing lists,needsFaq,fanoutsToUse's budget, fewer fan-outs than questions, two questions with one fan-out, one question with two, andlengthConflictwith two fan-outs;agent-write.test.ts: new page vs existing page;page.test.tsx: the detail sent;content-agent.test.js/content-writer.test.js:FANOUT_RULEin both suggestion prompts, the fan-out line in the new-page prompt, a second question dropped (short, past the limit, answered), and a question reworded kept;agent-suggestions.test.ts/suggestions.test.ts: the same over the API, andasksMoreThanOne.Known, not changed here: an insert can still carry a heading with two questions.
growsPastLimitdoesn't look at inserts either.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) (0 errors; the 6 warnings are in untouched files, as on main)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn testandyarn build;npm run format,npm run lintandnpm test.🤖 Generated with Claude Code