Skip to content

feat(content): export the page ready to paste, with its page fields (CE-057) - #1423

Merged
gkhngyk merged 163 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-export
Oct 23, 2026
Merged

gkhngyk merged 163 commits into
ansvisor:mainfrom
cihan-gyk:feature/quality-export

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

Content Editor Quality spec §7b, CE-057 Ready-to-publish export (part A). Behind NEXT_PUBLIC_CONTENT_QUALITY_PHASE; with the flag off, Export stays the Word / HTML / Markdown menu it was.

Stacked on #1422 (→ #1421 → … → #1411). Web only, no migration. Part B follows: Before you publish on Export with the "Ready to paste" row, and the opt-in "Add byline to content".

Export (_export-dialog.tsx) opens from the header and shows the page as it was when it opened.

  • Where it goes: Webflow · WordPress · Shopify · Google Docs · Word · Markdown · HTML. The last choice is remembered, and arrow keys move along them.
    • Webflow, WordPress, Shopify, Google Docs: copied as rich text (Clipboard API, else a copy event), to paste into the CMS's editor or a Doc. The three CMSs leave the page's H1 out, since their title field holds it. Where the browser refuses rich text, it copies the HTML and says so: "paste it into the editor's HTML or code view".
    • Word: a .docx with the page fields in a table on page 1, and the page from page 2.
    • Markdown: a .md with front matter (title, description, slug, author, date, image), and the title not again as an H1.
    • HTML: Copy HTML (the clean fragment), or Download HTML with the meta title, description and author in its head.
  • Placeholders never ship. With one open: "{n} placeholders are still open. Exports never contain [ ] text." Export waits for a choice:
    • Fill now selects the first one: in the page, or in the HTML view's text while that is open. One that only an HTML block holds is named as being there.
    • Export without them leaves out the sentence each is in. Sentences are read as a reader would (Intl.Segmenter), so "1.5 litres", "e.g." and "acme.com" don't end one. A placeholder outside a line, in alt text or in JSON-LD goes alone. A line, an item, a quote or a table row left empty goes too.
      • This is deterministic in Phase 1: sentences are left out, not rewritten by the agent, and the dialog says so ("left out of this export").
    • One in the title or a heading must be filled first; a heading has no sentence to drop.
    • Copy HTML in the header sends a page with a placeholder to Export (on HTML) instead of copying it.
  • Content · ready to paste:
    • Clean HTML, or "HTML blocks keep their own code" when a class, a style or a script goes out as written.
    • The links, from Trust's link reads: all answer / {n} don't answer / still being read / {n} couldn't be read. "Answer" is only said for links that were actually read.
    • The images' alt text.
  • Page fields · for your CMS's own fields, not the content: meta title, meta description, slug, author, featured image, each with Copy.
    • They are read from the page as it goes out, so placeholders left out are out of the fields too:
      • the description is the first paragraph's sentences up to 160 characters;
      • the slug is the live page's address part for an optimize draft (decoded, without index.html), else the title's;
      • the author or team byline;
      • the first https image.
    • Nothing is written for the page.

lib/content/ready-to-publish.ts holds exportPlaceholders, withoutPlaceholders, pageFields, withoutLeadingH1 and pasteChecks. draft-export.ts gains ExportFields for the table, front matter and head. <meta> values escape quotes.

Pre-push review: 3 high findings fixed:

  • fields that still carried placeholders;
  • placeholders that survived the strip with no check after it;
  • a sentence splitter that cut "1.5" or "e.g.".

Also fixed:

  • alt text and JSON-LD;
  • a leading script that DOMParser moved;
  • Fill now that did nothing in the HTML view;
  • meta quotes, heading leftovers and the duplicate H1;
  • the misleading rich-copy fallback;
  • slugs, the "Clean HTML" row, radio keys, the dialog description, empty rows, and the snapshot on open.

In local testing, the link row showed "1 link answers" while the reads had failed; the "read" count fixes that.

Not in this PR:

After review (2026-10-23):

  • The page is parsed in a document of its own, so nothing in it loads or runs.
  • JSON-LD is read by its string values (arrays never count), and Export without them keeps it valid JSON.
  • In titles and headings only the agent's three forms hold the export: [figure, source…], [name of a real person] and [quote from a real person…]. Quality's to-do and Fill agree.
  • A live page's Markdown gets lastmod instead of date.

Related issue

Drive spec Quality §7b, CE-057. No GitHub issue.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

How to test

  1. Set NEXT_PUBLIC_CONTENT_QUALITY_PHASE=1. Open a blog draft with a [name of a real person] in a paragraph, a link, and an image with no alt text.
  2. Click Export. You see the placeholder notice, Copy for Webflow disabled, the three checks and the page fields.
  3. Fill now selects the placeholder. Open Export again and choose Export without them: "The sentences with a placeholder are left out". Then Copy for Webflow and paste into a rich text editor: no H1, no placeholder sentence.
  4. Pick Word → Download: the page fields table on page 1. Pick Markdown → front matter, no # title.
  5. Put a placeholder in an H2: Export without them still waits ("…in the title or a heading: fill it first").
  6. Click Copy HTML in the header with a placeholder open: Export opens on HTML instead of copying.

Checked locally at 1024 px in light and dark, on a temporary demo draft (removed afterwards): steps 2–3 as above, with the toast "Copied for Webflow: paste it in.".

Checklist

  • web/ at the final commit: yarn lint (0 errors; 6 existing warnings elsewhere), yarn typecheck, yarn test (353 files, 3,149 tests), yarn format:check and yarn build pass
  • Tests:
    • ready-to-publish.test.ts (10): placeholders in words, alt text and JSON-LD; sentences with numbers, abbreviations and addresses; headings kept; a leading script; fields from the page; slugs; the H1; checks
    • draft-export.test.ts: front matter, head and quotes, the Word table on page 1
    • _export-dialog.test.tsx (7): the placeholder gate, fields after leaving out, the title and heading hold, the rich-copy fallback, the checks, fields with Copy, downloads, arrow keys
    • page.test.tsx: Export opens, Copy HTML goes to Export, Fill now selects, an HTML block's placeholder, the menu with the flag off
  • UI text in messages/en.json

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 23, 2026 02:24
The workspace's one AI budget (Improve, the Content Editor's AI and the
Action Center's task writer) had no meter: the first sign of it was an
"AI usage is used up" error. Migration 00242 records what each AI call
was for (prompt_improve_usage.feature, backfilled) and sums the period's
spend by feature (ai_usage_by_feature). GET /api/billing/ai-usage
returns the shares of the plan's budget, and the Billing page shows the
share used, when it resets and what used it, with Agent Chat noted as
running on the workspace's own key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The workspace's AI budget was checked by reading the period's spend; the
call's cost was written once the model answered. Calls running at once
(two tabs, a teammate, an Action Center sweep) all read the same spend
and all ran past the budget. 00243's reserve_ai_usage takes a
per-organization lock, reads the spend with the calls in flight, and
holds the call's estimated cost; reserveAiBudget turns the hold into the
real cost or releases it. Improve, the brief rebuild, Apply rules with
Agent, Start Agent and the Action Center task writer use it in place of
enforceImproveQuota, which goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes:
- Apply rules with Agent and Start Agent charge an answer the provider
  billed but that missed the schema (NoObjectGeneratedError), as Improve,
  the brief and the task writer do; before, the hold was let go and the
  call ran free.
- A call holds the org's median cost over its last 20 calls this period,
  never less than the model's typical cost, so calls in flight pass the
  budget by far less.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply rules with Agent makes at most 8 small edits a run, which can't
bring a long page to its Length (about 2% a run on prod). The Content
Agent can now rewrite the whole page in one background call, left as ONE
suggestion (kind 'page', migration 00247) to compare and accept or reject:
- POST /api/content-drafts/:draftId/rewrite, through Start Agent's claim,
  budget hold and background run;
- passages AI quotes today, tables, images, quotes and HTML blocks go to
  the model as [[KEEP n]] lines and come back as they were; a rewrite that
  drops one fails the run;
- one H1, only the page's own links and the ones offered, the editor's
  tags; the page as it was is kept on the suggestion (before_html).

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

Review fixes:
- Kept blocks are described under the page (a quoted passage's words, a
  table's rows, an image's alt) and their text counts toward Length, so a
  rewrite aims at the whole page's length; with Length off it keeps the
  page's own. A kept H1 stays first, and the page's language is kept.
- The answer is taken out of a code fence, text left at its root goes in
  paragraphs, and an answer in Markdown fails the run.
- The page's own links stay exactly as written (query and anchor too).
- Kept blocks go back untouched (an empty table cell stays), only the
  page's first H1 counts as its title, a page that writes "[[KEEP" gets
  markers of its own, and a page that is only kept blocks isn't sent.

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

The Rules tab opens with the agent's two ways to meet its rules: Apply
rules with Agent (small edits, up to 8 a run) and Rewrite the page to
these rules (the whole page as one change). The rewrite is recommended,
with a one-line reason, when the page is more than 30% off its Length or
4 rules or more are open.

A rewritten page comes back as one suggestion with its own bar over the
page: the characters before and after and the agent's reason, Compare
(the page and the rewrite side by side), Accept (History keeps the page
first), Reject, and Undo. A page that changed since the agent read it
isn't written over. The page waits for the rewrite with its own steps,
and a failed rewrite's Try again rewrites again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes:
- A page is compared with the one the agent read by its words, with a
  space between blocks, so stored line breaks and lists don't read as a
  change (Accept and Undo were refused on imported pages).
- One agent run at a time from the page; a rewrite never starts before
  the locked passages are read, and sends the editor's own locked keys.
- Accept holds the page still from the start and checks it again before
  putting the rewrite in; Undo puts the page back as it was (two H1s too),
  and the bar waits while the HTML view is open.
- No rewrite advice for an empty page or one too long to send whole; the
  rewrite mark survives a reload; the waiting view says the rewrite waits
  in the editor; Compare's links don't navigate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1, part 1 (CE-025, CE-026, §4): the agent row and the
rewrite bar become one card above the toolbar, in three states:
- waiting: "Content Agent has {n} suggestions for you", what they change
  and the rules they gain ("Rules 5 → 6 of 13"), with Review (scrolls to
  the first suggestion and marks it), Reject all and Accept all; a page
  rewritten shows its characters, with Compare;
- all reviewed: what was accepted and the rules met and still open, with
  Undo all and Run Agent;
- working: while Apply rules with Agent runs.
The tile moves a little (a soft ring, a blink, a spark; a sweep and a
breath while working), never a rotating ring, and not at all with reduced
motion. The card wraps on a narrow page; Accept all and Run Agent are the
primary buttons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Run Agent on the card keeps to one agent run at a time and says why it
  waits; Apply rules never starts beside another run or before the locked
  passages are read.
- Ghost buttons show their hover on the card's grey; the tile and its
  count are hidden from screen readers (the title says it) and the count
  is darker for contrast; "+N more" comes from en.json, the reason's first
  letter is upper-cased in the page's locale.
- Review picks the first open suggestion in the page's order and focuses
  it; the sweep shows on the light tile in dark mode; the spark is slower
  once all are reviewed; without motion the working line is a faint full
  line; "0 still open" isn't said.
- globals.css keeps its own lines; only the motion block is added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…split Run Agent

Content Editor v1.1 part 2 (CE-028–CE-031): the side panel's tabs become
Instructions · Sources · Live page. Instructions holds Brief | Rules, with
the rules still open on the tab and the segment. Each segment opens with a
status card: Rules has one split Run Agent ▾ (Fix open rules, or Rewrite
the whole page, which renames it "Rewrite page") in place of the two rule
buttons; Brief has Run Agent while empty and Rebuild brief once written.
Why the agent can't run is written under the card, and each card's ⓘ tip
opens below it. The brief shows "Not set yet" and its Length in characters
and about as many words; the toolbar counter adds the page's words.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Run Agent's choice is worked out once and falls back to Fix without a
  rewrite; once a rewrite starts, the button is back on Fix.
- ▾'s choices are menu radio items; Fix is off when only rules the agent
  can't fix are open, and the card says what to do instead.
- The reason line under the card stays mounted for screen readers; Rewrite
  from brief writes its reason too; the tab's count is read out.
- Brief | Rules switch with the arrow keys, one tab stop.
- An edited brief's rebuild question sits under the card; a brief without
  H2s says to rebuild it; an empty brief shows no origin line.
- Plural copy for the open suggestions and the counter's words; rule names
  joined by the formatter; Run Agent's tip leaves ▾ out without a rewrite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1 part 3 (CE-032, CE-034): under each Run Agent card,
"Uses your data: 1 prompt · 21 fan-outs · 20 cited pages · 10 Search
Console queries · Edit sources", counted as the Sources tab keeps them, so
turning one off lowers it at once. The Sources tab carries its count, and
its top says "N sources in use" and when the Content Agent last wrote from
them (its latest suggestions or the brief it built). A first visit's note
at the top of Instructions says the agent writes from the person's data;
closing it is kept in their own user metadata.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- "Last used by Content Agent" also counts the agent writing the page
  (agent_state_at: Start with Agent, Rewrite from brief on a new page),
  not a run that failed; a value that isn't a date is skipped.
- The latest batch's time is its first suggestion's, not a sort per render.
- Tests: the Brief segment's line, no line while the sources can't be read,
  the tab's count, the note showing again after a failed write, and a
  suggestion read with its createdAt.

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

Content Editor v1.1, CE-033 (server): Fix open rules, Start with Agent and
Rewrite the whole page read the sources the Sources tab keeps, numbered
S1, S2… (content-sources.js). Each suggestion keeps the sources it names
and the words each supports (content_draft_suggestions.sources and
source_marks, 00248); a page rewritten whole keeps its sources.

No number without a source: the model reads a source by its words only, so
a number the agent adds must be the page's, the brand's, the brief's, the
rules', today's, or in a source's own words (then marked to it). A
suggestion with any other number is not kept; a page written whole gets a
placeholder in its place. Source numbers written into the words are taken
out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1, CE-033 (web) and the rest of CE-034: under each
suggestion, "Based on" chips name the sources it used (number, kind, name;
the Sources tab's details on hover), and a small number marks the words
each supports. A click on either opens Sources on that row, scrolled to
and ringed for a moment, once. The agent card adds "built from N of your
sources · See sources". Fix open rules sends the kept sources, and the
first-visit note says every change shows the sources it used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor v1.1, CE-027/035 (server): each Content Agent run (Fix open
rules, Start with Agent, Rewrite the whole page, the brief) is written in
content_agent_runs (00249) with its steps named by the data it reads
("Reading 20 cited pages", "Matching 21 fan-outs", "Writing 3 changes") as
it reaches them. POST /api/content-drafts/:id/stop marks the run stopped
and aborts its model call; the run checks before it keeps anything, so a
stopped run changes nothing (no suggestions, page, brief or History).

A run that can't be written still runs; runs a stopped server left are
closed when the next starts, and Stop ignores them. Background runs are
written before Start answers, so Stop finds them at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stop also clears the draft's 'writing' state at once: a background run lets
go once it sees the stop, but one no server holds any more never would, and
the waiting page would wait out the 10 minutes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p it (CE-027, CE-035)

The agent card, the brief and the waiting page show the run's real steps
(content_agent_runs, read from the browser every second) and a Stop button
that ends the run through the API proxy, leaving the page as it was. A dashed
decoration under the H1 says where Fix is drafting, and the agent's dots
replace every spinner on its buttons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h (CE-030)

When the brief is rebuilt, the server reads the first few cited pages kept
in Sources (only addresses AI answers cited for the brand, never the draft's
own page), counts their main text as the Rules tab counts length, and saves
the median as brief.citedLength. The Brief tab says "From the rules · cited
pages average N characters"; with fewer than two pages read it stays "From
the rules". textLength moves to page-content.js to avoid an import cycle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	server/src/lib/content-writer.js
#	server/src/lib/content-writer.test.js
#	supabase/schema.sql
…le it writes

content_drafts.agent_run ('write' or 'rewrite', in 00247 and its guard) is
set when Start or a rewrite claims the draft, so every device knows a failed
rewrite from a failed Start. Fix open rules and the MCP suggest call answer
409 'writing' while a run holds the draft, so its answer is never dropped
after it was charged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le it writes

content_drafts.agent_run ('write' or 'rewrite', in 00247 and its guard) is
set when Start or a rewrite claims the draft, so every device knows a failed
rewrite from a failed Start. Fix open rules and the MCP suggest call answer
409 'writing' while a run holds the draft, so its answer is never dropped
after it was charged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st batch's rows

The editor reads content_drafts.agent_run, so a failed rewrite is tried again
as one on every device (the localStorage mark is gone). Fix open rules' new
409 'writing' says the agent is already writing. getDraftSuggestions finds
the latest batch first and reads only its rows, and Compare's links can't
take focus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The card's Run Agent writes its reason in the card's second line (amber, tied
to the button by aria-describedby) instead of a hover title, and is turned
off when the only rules left open are ones the agent doesn't fix (one H1),
as the Rules card does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 24 commits October 23, 2026 23:18
ansvisor#1416's review fix reads "1 of 1 dated source is over 24 months old".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its to-do text names who can complete the profile when they can't.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ber can edit the author

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ansvisor#1400 adds the column to 00249.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Fixed, and main merged.

  1. Inert parse: fragment() parses into a document of its own (document.implementation.createHTMLDocument('')), so nothing in an HTML block loads or runs. A leading script stays first. Tests check ownerDocument !== document and the script.
  2. JSON-LD by its strings: placeholders are looked for in each string value, so sameAs, @type and mainEntity arrays never count. Export without them clears them inside the strings and writes the JSON-LD again (jsonLdText, moved out of normalizeJsonLd). A JSON-LD that doesn't parse is left as written and counts for nothing. Tests: sameAs / @type arrays, a FAQPage that stays valid JSON, a broken one.
  3. Brackets a person writes: option 1.
    • The server's guards write three forms: [figure, source], [name of a real person] and [quote from a real person, with its source].
    • The writer, agent and rewrite prompts also let the model write other bracketed text ("[price]").
    • AGENT_PLACEHOLDER (in placeholders.ts, with the "[figure, source, …]" variants) holds titles and headings only for those three forms. "Best CRM tools [2026 Update]" or "[Step-by-Step Guide]" no longer hold the export.
    • Quality's to-do and Fill/Show apply the same rule, so all counts agree.
    • Tests cover the person's brackets and the agent's forms, in headings and the title.
  4. Markdown date: a new page gets date; an optimize draft gets lastmod, as Before you publish does. Tested.
  5. Doc comment: draftHtmlDocument's is back on its function.

@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. All items done.

  • Inert parse:
    • fragment() now parses into a document of its own (ready-to-publish.ts:22-27), and the test checks ownerDocument !== document.
    • I followed every path that reads the page in this stack: Export, Copy HTML, Ready to paste, the byline and Next step. Each one parses in a document of its own: fragment(), DOMParser in cleanHtml / draftBlocks / firstImage / pagePlaceholders, or a <template>. blankCode and the H1 search only scan the string.
    • What comes out is only ever a string (innerHTML / outerHTML) or a count. The byline <p> is created in the fragment's own document, so nothing is moved into the page.
  • JSON-LD:
    • It's read by its string values only, so arrays and objects never count.
    • Leaving placeholders out rewrites the JSON through jsonLdText, which keeps <, > and & escaped and the JSON valid.
    • A JSON-LD that doesn't parse counts for nothing.
  • Brackets in titles and headings: only the three forms the agent writes (AGENT_PLACEHOLDER) count there. The same rule applies to pagePlaceholders, showFirstPlaceholder, exportPlaceholders, titlePlaceholders and the HTML view's Fill now (#1426).
  • Markdown: a new page's front matter gets date; an optimize draft gets lastmod.
  • Doc comment: draftHtmlDocument's is back on its function.

For a follow-up (low, fine to merge without them):

  1. Before you publish still reads the title with the old rule.
    • titleHasPlaceholder (page-schema.ts:34-37) is built on PLACEHOLDER.
    • So for "Best CRM tools [2026 Update]", the Article JSON-LD leaves out headline (:102) and says the title still has a placeholder. Ready to paste and Export pass the same title.
    • Fix: build ONE_PLACEHOLDER from AGENT_PLACEHOLDER, and add that title to its test.
  2. The three follow-ups from your #1427 reply:
    • Links row: Export's links row says all {count} links are still being read while any read is pending (_export-dialog.tsx:258-262). Use the same split as #1426's readyRow.
    • Re-reads on render: pasteChecks runs on every render while Export is open (_draft-editor.tsx:1936). Put it in a useMemo.
    • English team name: the page fields' team fallback is English ("{brand} Team", _draft-editor.tsx:1935). It goes into the CMS author field, the Markdown front matter and <meta name="author">. Use the brand name alone, or add a team form per language next to #1427's BYLINES.

Merge commits: 8c7f8db and 4f08db3 carry no hidden changes. Merging their parents again gives the same trees.

Merge state: merges cleanly on main 8cde68c (main is already in the branch). Web only, no migration.

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