Skip to content

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

Merged
gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/agent-run-feedback
Oct 23, 2026
Merged

gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/agent-run-feedback

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The editor now says when an agent run stops at its most, and when the Length rule can't fit what the other rules ask for.

Stacked on #1383 (C1, on #1374 → #1372 → #1371 → #1369 / #1370). This PR's own change is b4974d5. Merge after #1383.

On prod, "Apply rules with Agent" left exactly 8 suggestions on every run, and the same rules stayed open.

  • Why: 8 is the API's cap per run (MAX_AGENT_SUGGESTIONS). Nothing said so, so the run looked finished.
  • A second cause: a 2,000-character Length with 4 fan-out H2s, 5 FAQ questions and a summary can't all be met at once. The rules gave no sign of that.

Run feedback

  • AGENT_RUN_MAX = 8 in lib/content/suggestions.ts mirrors the server's cap.
  • Toast: after Apply rules with Agent, a batch of 8 says "Content Agent suggested 8 changes, the most one run makes · review them, then run it again for the rules still open".
  • Agent bar: once a batch of exactly 8 is decided and rules are still open, the bar adds "a run makes at most 8 changes: run it again for the rest".
    • It checks for exactly 8 because an API (MCP) batch can hold up to 20 and says nothing about a run.

Length conflict note

  • lengthConflict(statuses, fanouts) in rules.ts estimates the least text that the open structure rules need:
    • fan-out H2 sections: min(asked, fan-outs there are) × 200;
    • FAQ questions: max(FAQ, buying FAQ, fan-out FAQ) × 150;
    • a summary: 100.
  • The amounts are kept low on purpose. A heading with two short sentences is about 200, and a question with a one-sentence answer is about 150.
  • It returns a value only when that need is over the most text Length allows (+20%).
  • It stays quiet when:
    • Length is off;
    • the page already meets all those rules;
    • a rule can't be checked yet (no fan-outs).
  • The Rules tab shows it as an amber note under Length, with a dark variant: "…take about 850 characters, more than Length allows (up to 720). Raise Length, or ask for fewer."

No migration, no server change.

Note for review: I computed the note against every page type's default set (untouched rules, a page not meeting them yet). Four e-commerce types show it once the brand has a few fan-outs; their default Length is short for 4 fan-out H2s + 5 FAQ questions + a summary:

Page type Default Length (max) Note shows from Need at 4 fan-outs
category_page, collection_page 800 (960) 1 fan-out 1,650
sizing_guide 1,000 (1,200) 2 fan-outs 1,650
product_page 1,200 (1,440) 3 fan-outs 1,650

The other 16 types stay quiet at 0–6 fan-outs. I think the note is right there: those defaults can't all be met. A follow-up could lower those types' fan-out H2 / FAQ defaults or raise their Length. That's a product call, so I left the defaults as they are.

Follow-up idea, not here: the hint is a size check on the batch. A run that splits replaces can reach 8 rows without the model hitting its cap. An exact signal would need the API to return a full flag.

Related issue

Content Agent rule gaps, item C ("8 per run · run again" and rule conflicts), 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. Open a Blog post draft with no fan-outs. In the Rules tab, set Length to 600.
    • An amber note under Length says the FAQ questions and summary take about 850 characters, more than Length allows (up to 720).
    • Set Length to 1,000: the note goes.
  2. Run Apply rules with Agent on a page with many open rules.
    • If it leaves 8 suggestions, the toast says that's the most one run makes.
    • After deciding them all, the agent bar says to run it again for the rest.

There are no AI keys locally, so I checked the bar and the note with a temporary draft holding 8 decided suggestions (deleted afterwards).

Tests:

  • rules.test.ts: lengthConflict — the estimate, rules off or met, no fan-outs, Length off;
  • _rules-tab.test.tsx: the note, and none with Length off;
  • page.test.tsx: the toast and the bar for a full batch, and nothing for a batch of 2.

Checked in the browser at 1024 px, in 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 (2,870 tests) and yarn build, before the review fixes;
  • the changed test files, again after them.

🤖 Generated with Claude Code

cihan-gyk and others added 14 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]>
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]>
…th 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]>
@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 C2: the editor says when an agent run stops at its 8-change cap, and the Rules tab warns under Length when the open structure rules can't fit in it (web only, no migration). Stacked on #1383. The PR body has a table of the four e-commerce page types whose default sets trigger the note — a possible defaults follow-up, your call.

gkhngyk
gkhngyk previously approved these changes Oct 23, 2026

@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. Two low items:

  1. The note always names all three parts (web/messages/en.json:4076).

    • "The fan-out H2s, FAQ questions and summary these rules still ask for…" shows even when only some of them count. In this PR's own test case (a blog post with no fan-outs), the 850 is only FAQ questions plus the summary, yet the note still names fan-out H2s.
    • Fix: say "The sections and questions these rules still ask for take about {need}…". Or pass which parts counted and pick the wording from that.
  2. The default e-commerce sets trip the note on a brand's first fan-out. The PR description already lists these.

    • category_page and collection_page show it from the first fan-out. sizing_guide shows it from 2 and product_page from 3.
    • So most new drafts of those types will show the amber note on untouched defaults.
    • Decide whether to lower those types' fanoutH2 / FAQ defaults (or raise their Length) here or in a follow-up. Merging as-is means a warning on most such drafts until then.

Checked and fine:

  • lengthConflict.
    • Rules that are off, rules with an info status, and rules with values of 0 or less add nothing.
    • fanoutH2 is capped at the fan-outs there are, and fanoutFaq counts only when there are fan-outs. The FAQ rules share one section through max.
    • When every counted rule is met, the note is quiet. The ceiling is lengthBand(target).max, and a page brought in (#1383) is measured against its own length.
  • Run cap. AGENT_RUN_MAX matches MAX_AGENT_SUGGESTIONS, and keepSuggestions caps the rows at 8 even after a split. So the toast's >= and the bar's === agree for Apply rules and Start Agent batches.
  • UI and i18n. The new keys are in en.json with ICU numbers. The amber note follows the editor's existing warning colour and has a dark variant, and it shows only while Length is on.
  • Tests. They cover the estimate, rules off or met, no fan-outs, Length off, the note, and the toast and bar for a full batch vs a batch of 2.

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