Repository navigation
feat(content): let agents link over the API, to the brand's pages and the draft's sources - #1372
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]>
|
@gkhngyk Content Agent rule gaps A2, stacked on #1371. MCP agents get the same links as the in-app agent:
Testing it end to end needs an API key, so it is yours if you'd like to try it. The tests and a sanitize-html probe cover it. A review pass before pushing asked for three changes, now in:
|
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. The same two follow-ups as #1371, on the web side:
-
Redirecting pages as targets (
web/src/lib/mcp/content.ts:259). Keep 2xx only (fetch_status.lt.300), as in #1371, so the API and the in-app agent offer the same list. -
A link in a heading's split-off answer is lost (
web/src/lib/content/agent-suggestions.ts:188,:201). The answer paragraph is built fromescapeHtml(answered[2]), so a listed link inside it is dropped. Fix: carry the answer's links into the paragraph by offset, as in #1371.
Checked and fine:
- API scope.
getContentDraftForandsuggestContentChangesForboth resolve the draft throughdraftFor, which checks the key's organization (brands!inner). Only after that doeslinkTargetsOfreadsite_pagesand the sources by that draft'sbrand_idandid.- API keys are scoped to an organization, so there is no brand scope to check as well.
- The REST twins call the same functions.
- Only listed URLs survive.
- In sanitize-html's
transformTags.a, a link stays an<a>only when its key is in the allow-list. It then keeps onlyhref, set to the target's URL. Anything else becomes a droppedspanand keeps its words. - Targets come from
linkHref, which is http(s) only, sojavascript:and other schemes can't come through. - Links in h2–h4 are stripped, and links with no words go through
exclusiveFilter. - When no suggestion contains
<a,linksis null and every link is unwrapped. That fails safe.
- In sanitize-html's
- Parity with the server.
linkKey,linkHref, the caps (40 and 20) and the filters matchcontent-links.js.- The competitor and own-domain checks,
classifyDomain/normalizeDomainhere andownDomainMatcheron the server, use the same host-or-subdomain rule. inlineTextreads sanitize-html's output, with entities decoded, into the same offsets as cheerio's. It handles nested anchors the same way too.
- Writes.
after_linksis sliced to 20 and set on replaces only, within 00240's check. - Cost. There is no LLM call.
get_content_draftreads the targets alongside the locked passages, so it waits on the slower of the two. Thecontent_draft_sourcesread takes 0.15 s warm and 1.3 s cold on the largest brand.suggest_content_changesskips it when nothing links. The response grows by at most 60 short entries.
gkhngyk
left a comment
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).
Summary
Agents working through the editor API (MCP
suggest_content_changes) can now link: to the brand's own pages and the draft's sources, as the in-app Content Agent does since #1371.get_content_draft(and its REST twin) returnslink_targets:own_pages: the brand's pages fromsite_pages, the most cited and visited first. Up to 40; failed fetches and the draft's own URL are left out.sources: the draft's sources from thecontent_draft_sourcesRPC plus the ones the person added. Up to 20, without the brand's or a competitor's domains, and without the ones left out.suggest_content_changes<a href="URL">words</a>. A link stays only when its URL matches a target (linkKey: host without www, no tracking parameters, hash or trailing slash), and it keeps the target's clean URL.no_change, as before.after_links(00240, from feat(content): let the Content Agent link to the brand's pages and the draft's sources #1371), by offset into its words. An insert keeps them in its HTML. The editor puts them on as link marks, as for the Content Agent.<a, so most calls don't run the sources RPC.Code
web/src/lib/content/link-targets.ts(new) mirrorsserver/src/lib/content-links.js:linkKey,linkHref,linkAllowListandpickLinkTargets, with competitors matched throughclassifyDomain/normalizeDomain.agent-suggestions.ts:cleanInsertHtml(html, links)uses sanitize-html.ais renamed to a droppedspanunless allowed, then links inside h2–h4 are stripped.inlineTextreads the sanitized inline HTML into words plus link offsets, with the same offsets as the server'sinlineText.splitReplaceandkeepAgentSuggestionspass the allow-list through.lib/mcp/content.ts:linkTargetsOf(draft). A failed read is logged and leaves its list empty.get_content_draftreads targets, locked passages and open suggestions in parallel.link_targetsURLs.No migration.
Related issue
Content Agent rule gaps, item A (part 2), 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
With an API key (MCP or the REST twin):
get_content_drafton a draft:link_targets.own_pageslists the brand's pages, andlink_targets.sourceslists the draft's cited sources, with no competitor and no left-out source.suggest_content_changeswith a replace linking words to one of those URLs: the card in the editor underlines the words and lists "Links: …", and accepting it adds the link.droppedasno_change.Not tried end to end locally: that needs an API key (gkhngyk's). Covered by tests:
link-targets.test.ts: targets, competitors with a path, left-outs, no sources without their read;agent-suggestions.test.ts: kept and invented links, links in headings, empty links, inline offsets;content.test.ts:link_targetsinget_content_draft,after_linkswritten, no sources read when nothing links.The pre-push review also ran ~15 hostile inputs through the real sanitize-html 2.17 (
javascript:, made-up domains, extra attributes, a duplicate href,<a>in ansvg, uppercase tags in headings): no link outside the allow-list survived. It also confirmed the offsets match the server'sinlineText.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: web
yarn test(324 files, 2,854 tests) andyarn build.🤖 Generated with Claude Code