Skip to content

feat(content): fit the editor header to its width, its icon buttons labelled on hover and focus (Next step basket, part 2) - #1429

Merged
gkhngyk merged 181 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-header-layout
Oct 24, 2026
Merged

gkhngyk merged 181 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-header-layout

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Summary

Content Editor Next step basket, part 2: the header layout from the spec's §3b (Drive CONTENT-EDITOR-next-step-spec.md).

Builds on #1428 (merged); main is merged in, so the diff is this part's 8 files. Web only, no migration.

The header is laid out, left to right: title + save state · Next · {step} · N running · History · Copy HTML · Export · Mark ready. The AI usage meter's slot (between "running" and History) comes with the AI usage display work.

Title

  • It takes the room left, at least 140 px from 1024 px (96 px narrower, less while the save state needs its words), and ends in "…". It never pushes, overlaps or wraps the buttons.
  • Hover shows the whole title.
  • A click puts the caret at the end of the block the title is read from, as draftTitleFromDoc picks it: the first H1 with words, else the first heading, else the first line. With the HTML view open, it says to rename it there.
  • The save state sits beside it. Narrower than 1024 px, "Saved" becomes a dot; the words stay for screen readers and on hover, and a conflict or a failure keeps its words.

Buttons

  • History, Copy HTML, Export are icon buttons.
    • Their label shows on hover and on keyboard focus, with the hint as a second line. It uses the app's tooltip (components/ui/tooltip.tsx, in _header-tip.tsx), so Escape closes it.
    • Each keeps its aria-label, and the hint is its description for screen readers.
    • History's hint says why it waits while the HTML view is open or a restore runs.
  • Mark ready stays the one black text button.
    • Once marked it reads Ready in green.
      • A click moves the page back to review, only while it is still ready. The new unmarkContentDraftReady updates where status = 'ready', and returns the status the page has.
      • A page published from the Library meanwhile reads Published, and the toast says so.
      • The task Mark ready completed in Action Center stays done.
    • A published page reads Published. It isn't undone here, and stays focusable (focusableWhenDisabled), so its tip says where to change it.
  • "1 running" (with the Quality flag) shows while Fix open rules or the brief works, the runs whose steps and Stop the basket shows. A click opens the basket; the count is on hover.

Narrower than 1024 px, nothing disappears; the buttons shorten:

Checked in the browser with a 130-character title. At 1024, 900 and 768 px the header stays one line (28 px) and nothing overflows. The title gets 289, 249 and 117 px, and the save state never reaches Next.

These layout changes apply with the flag off too (one header, not two). Next and "running" stay behind NEXT_PUBLIC_CONTENT_QUALITY_PHASE, with the basket.

Pre-push review: no high findings. Fixed:

  • "running" showed during runs the basket can't follow;
  • the title's minimum moved onto its own box;
  • the app's tooltip instead of a CSS-only one (Escape, touch, screen readers);
  • Ready → review guarded on the status;
  • History's reason;
  • Published focusable;
  • the title click follows how the title is read.

Related issue

Drive spec Content Editor › Next step basket §3b. No GitHub issue.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

How to test

  1. Open a draft with a very long title at 1024 px. The title ends in "…" on one line, and the buttons stay in place. Hover shows it whole; a click puts the caret at the end of the page's H1.
  2. Hover or Tab onto History, Copy HTML and Export: each shows its label (and hint).
  3. Make the window narrower than 1024 px: Mark ready becomes ✓ with its label on hover.
  4. Mark the page ready: the button reads Ready, in green. Click it: "Back in review.", and Mark ready is back.
  5. With the Quality flag, run the agent: "1 running" shows; a click opens the basket with its steps and Stop.
  6. Check light and dark.

Checked locally at 1024, 900, 860 and 768 px in light and dark, on a temporary demo draft (removed afterwards with its History version).

Checklist

  • web/: yarn format:check, yarn lint (0 errors; 6 existing warnings elsewhere), yarn typecheck, yarn test (363 files, 3,279 tests) and yarn build pass
  • Tests:
    • _header-tip.test.tsx: the hint as the button's description, shown on hover and keyboard focus, closed with Escape, narrow-only
    • content-drafts.test.ts: unmarkContentDraftReady moves only a ready draft, and returns a published one's status
    • page.test.tsx:
      • Ready after Mark ready, and back to review;
      • a failed move keeps Ready;
      • published meanwhile;
      • Published focusable;
      • the title click with an H1, with no H1, and with the HTML view open;
      • History's reason;
      • "1 running" while Fix works, opening the basket;
      • Copy HTML found by its label
  • 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 16 commits October 23, 2026 23:26
…rt-byline

Renumbers our migration 00257→00261, as asked in review: main took 00251 in ansvisor#1425.
…to export

The dialog focuses its button after it opens; checking at once failed now
and then under load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With ansvisor#1411 below it, the editor reads the draft's Language rule first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ld a skip until every read is in

Review fixes for the Next step basket:
- focus goes back to the Next button only from inside the basket or from
  nowhere (Base UI's own rule); after Skip, the new step's button takes it
  and the step is read out
- stale skips are dropped only once the sources, the site's trust and the
  link reads are in
- an empty page is read past the block its title comes from
- Before you publish and Mark ready are held as the header's Mark ready is
- Rewrite page sits beside Fix open rules where the Rules tab recommends it,
  and "If you see…" takes its count from REWRITE_OPEN_RULES

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…abelled on hover and focus (Next step basket, part 2)

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 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. The layout, HeaderTip, and the guarded unmarkContentDraftReady (.eq('status', 'ready'), falling back to the status the draft has) all read right. The top merge of main adds nothing hidden: the diff against main is exactly the change in 489d2dd. Three small follow-ups, none blocking:

  1. Published is green, and looks clickable. _draft-editor.tsx:1989 gives Ready and Published the same emerald classes. The app's status colors (components/content/draft-badges.tsx:15, DRAFT_STATUS_BADGE) make Published blue, and the editor's own DraftStatusBadge right under the title (:2048) shows it in blue. Also, focusableWhenDisabled sets aria-disabled rather than :disabled, so on Published (and while unmarking) the button keeps the base cursor-pointer and the hover:bg-emerald-100 tint, and disabled:opacity-100 never applies. Fix: take the colors from DRAFT_STATUS_BADGE[status] (or add a blue set for Published), and add aria-disabled:cursor-default with no hover tint while aria-disabled.

  2. The title click doesn't always land where the title comes from. renameInPage (_draft-editor.tsx:1782) only collects top-level textblocks. draftTitleFromDoc (lib/content/editor.ts:86) falls back to any top-level block with words, so a list, a quote or a table counts too. On a page with no heading that opens with a list, the title is the list's text, but the caret goes to the next paragraph (or to the start). Fix: drop node.isTextblock && and keep the textContent.trim() check. TextSelection.near(doc.resolve(end), -1) already lands at the end of the last text inside a list, quote or table.

  3. Nit: _draft-editor.tsx:1918-1919 are two comments that say the same thing about the running chip. Keep one.

@gkhngyk
gkhngyk merged commit 1e25758 into ansvisor:main Oct 24, 2026
5 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
ansvisor#1432 is on main (squash-merged), with ansvisor#1429–ansvisor#1436 around it; this
branch's own changes (part 5 and its follow-up) are applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
ansvisor#1433 is on main (squash-merged), with ansvisor#1429–ansvisor#1436 and ansvisor#1442/ansvisor#1444; this
branch's own change (Send to CMS part 2) is applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
…library

ansvisor#1438's branch now has main (ansvisor#1429–ansvisor#1436, ansvisor#1442, ansvisor#1444); this branch's own
changes (Send to CMS part 3a) are applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
…-bulk

ansvisor#1439's branch now has main (ansvisor#1429–ansvisor#1436, ansvisor#1442, ansvisor#1444); this branch's own
change (Send to CMS part 3b) is applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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