Repository navigation
feat(content): aim an optimized page's Length rule at its own length - #1383
Merged
Merged
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]>
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]>
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]>
Collaborator
Author
Merged
8 of 12 tasks
gkhngyk
previously approved these changes
Oct 23, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good. One low follow-up:
importLengthaccepts far more than the Length rule takes (web/src/lib/content/rules.ts:317).- The schema allows
.min(1).max(10_000_000), whilestartingRulesclamps to 100–50,000. A value saved throughsaveDraftRulesoutside that range goes straight intoruleSet's Length value, and from there into the Rules tab. ruleLengthstill clamps what the agent and the counter use.- Fix: bound the schema to 100–50,000.
RULE_LENGTH_MIN/MAXare declared below the schema, so either move them up or use the literals.
- The schema allows
Checked and fine:
- Where it's set.
createContentDraftandstartDraftFromActionmeasure the sanitized body. They writerulesonly when there is an import length, so other drafts keep the column default.- The insert in
startDraftFromActiongoes through the admin client, but the rules object is built on the server.
- Kept through every path.
editedspreadseffective, so the import length survives every rule change.pickSetandresetcarry it over explicitly.effectiveRulesandpickSetdrop only My rules' Length value and keep its on/off.setToSaveputs the workspace's own value back. A value the person typed is saved as theirs, which the tests pin.
- Interaction with the Length rule on main (#1357/#1366).
- The counter colour comes from
lengthWarns, the Length status, and the counter's target fromruleLength. Both read the sameruleSetvalue, so they agree. activeRulesdoesn't mark the import length as changed, and Reset returns to it.
- The counter colour comes from
- The count.
pageTextLengthadds one space per block over TipTap's count, which is well inside the ±20% band. - Other readers. Nothing else builds the rule set from a draft's
rules. MCP and the server don't parse it, so an optional field is safe. - Cost, i18n and tests.
- There is no LLM change, and the Length hint is updated in
en.json. - Tests cover
effectiveRules,overridesForImport,setToSave,pageTextLength, the clamp, both server starts and the dialog's request.
- There is no LLM change, and the Length hint is updated in
5 of 12 tasks
gkhngyk
approved these changes
Oct 23, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
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).
10 of 14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A page brought in to optimize now aims its Length rule at its own length, not at a new page's target.
On prod, an 18,000-character page imported to optimize had a Length rule of 2,000 (My rules) or 3,000 (the blog post default).
What changed
optimizeand a page's text stores that text's length asrules.importLength. The length is clamped to the Length rule's 100–50,000 range.startingRules()inlib/content/rules.ts, which the server actions (createContentDraft,startDraftFromAction) and New content's "Who does it: Agent" request all use.ruleSet(type, { length })), and is met within ±20% as before.overridesForImport).setToSave), so saving from an imported page doesn't erase it.agentWriteRequest).pageTextLength()counts the text as the editor does, plus one space between blocks. On a 5.5k-character page, the editor counted 5,515 and the stored value was 5,527.There's no migration, since
importLengthis an optional field in the existingrulesjsonb (00213 only checks it is an object of at most 32 KB). Drafts made before this keep the type's length.Follow-up, not in this PR: an Optimize draft made by MCP
create_content_draftdoesn't getimportLength. There the agent writes the body, so it has no imported page to measure yet.Related issue
Content Agent rule gaps, item F (folded into C), 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
Tests:
rules.test.ts:effectiveRules,overridesForImport,setToSave,pageTextLength, andstartingRules, including the clamp;content-drafts-start.test.ts: paste/import, Start from an opportunity, an Action Center task, and no rules without the page's text;new-content-dialog.test.tsx: the Agent request.Checked in the browser at 1024 px, in light and dark themes (Rules tab, Length 5527). The temporary draft was deleted.
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 test: 2,865 of 2,866 passed in the full run. The Library export test ("reads a long list's pages fifty at a time") hit the 5 s timeout under memory pressure. It's untouched here and passes alone (21/21).yarn build.🤖 Generated with Claude Code