Skip to content

feat(content): show the Content Agent as a card over the page (CE-025, CE-026) - #1395

Merged
gkhngyk merged 25 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-agent-card
Oct 23, 2026
Merged

gkhngyk merged 25 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-agent-card

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Content Editor v1.1, part 1: the agent row becomes an agent card. It says how many suggestions wait, what they change and the rules they gain, then what was accepted and what is still open, and shows the agent while it works.

Stacked on #1394 (Rewrite the page, web), which is stacked on #1393 → #1387. Merge after them. Spec: Drive › Content Editor › CONTENT-EDITOR-v1.1-spec.md §2 and §4, with the mockup CONTENT-EDITOR-v1.1-mockup.html (2026-10-23).

Part 1 of v1.1 covers CE-025, CE-026 and §4. Next:

  • part 2: the Instructions tab and the split Run Agent button;
  • part 3: the data the agent uses;
  • part 4: progress steps and Stop (server);
  • part 5: "Based on" chips.

The card (_agent-card.tsx), above the toolbar, replaces the agent row and the rewrite bar. It has three states:

  • Waiting.
    • Title: "Content Agent has {n} suggestions for you".
    • Second line: what they change, in the agent's words ("Remove an AI trace (rule) · +1"), plus the gain in green ("Rules 5 → 6 of 13") and the action they came from.
    • Buttons: Review scrolls to the first open suggestion and marks it for a moment; Reject all; Accept all (the primary, black).
    • A rewritten page shows its characters before → after and the reason, with Compare / Reject / Accept.
  • All reviewed.
    • Title: "All suggestions reviewed".
    • Second line: "2 accepted · Rules 6 of 13 · 7 still open". A full run's batch still says to run it again.
    • Buttons: Undo all and Run Agent (fix the open rules).
  • Working. While Apply rules with Agent runs: "Content Agent is working", three bouncing dots and a sliding line. The real step chips and Stop come in part 4: they need the agent's progress events.

The gain (rulesAfter) counts each open rule an open suggestion says it meets, once.

Motion (CE-026). The tile:

  • breathes softly (a ring that grows out of it, never one that rotates);
  • the robot blinks and a spark by its antenna twinkles; green and slower once all are reviewed;
  • while working, a sweep crosses it and it breathes, and the robot looks around.

The keyframes are --animate-agent-* in globals.css. Every moving element also has motion-reduce:animate-none (or hidden), so reduced motion stops all of it.

Layout.

  • The text gets a line first, so on a narrow page the buttons go under it, inside the card. I checked this at 760 px with the side panel open, and at 1024 px.
  • The card uses theme tokens (bg-muted, border), so light and dark follow the app. The tile is bg-foreground (black in light), and the count badge is amber.

§4 primary buttons. Mark ready, Accept all / Run Agent on the card, and Accept on each suggestion are the black primaries. The panel's Run Agent comes with part 2.

Also:

  • _agent-bar.tsx is removed;
  • the rewrite bar's Compare dialog is now PageCompareDialog;
  • the old bar's unused copy is removed from en.json.

Related issue

Content Editor v1.1 (Drive spec, 2026-10-23): CE-025, CE-026, §4. No GitHub 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 draft with an open agent batch. The card reads "Content Agent has 2 suggestions for you", with what they change and the green gain. Review scrolls to the first suggestion and rings it.
  2. Accept all. The card reads "All suggestions reviewed · 2 accepted · Rules 6 of 13 · 7 still open", with Undo all and Run Agent.
  3. Press Apply rules with Agent in Rules. The card shows the agent working until its batch lands.
  4. With reduced motion on, nothing on the card moves.

I checked steps 1–2 in the browser on the dev DB with a temporary draft and batch (deleted afterwards): light and dark themes, at 1024 px and 760 px.

Tests:

  • _agent-card.test.tsx: rulesAfter; the waiting state's line and buttons; all reviewed with Run Agent; working with nothing to press; the page variant; reduced motion on every moving element;
  • page.test.tsx: the card's copy; Review scrolling to and marking the first suggestion; the card working while Apply rules runs, then its batch.

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,916 tests) and yarn build.

🤖 Generated with Claude Code

cihan-gyk and others added 11 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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This is Editor v1.1 part 1 of 5, from the user's Drive spec of today (CONTENT-EDITOR-v1.1-spec.md §2 + §4). The agent row becomes an agent card: waiting, all reviewed, and working. It has a Review button and a rules gain, and its motion stops with reduced motion. It is stacked on #1394. Web only. I checked it in the browser in light and dark themes at 1024 px and 760 px. Parts 2–5 come next: the Instructions tab with a split Run Agent, the data the agent uses, progress steps with Stop (server), and "Based on" chips (server).

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 23, 2026
@cihan-gyk cihan-gyk changed the title feat(content): show the Content Agent as a card over the page (Editor v1.1, 1/5) feat(content): show the Content Agent as a card over the page (CE-025, CE-026) Oct 23, 2026
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. One small follow-up:

  1. (low) The card's Run Agent can't say why it won't run. Its reason is only a title (_agent-card.tsx:340, :376). It also stays enabled when the only rules left open are ones the agent can't fix (One H1). In that case a click just raises the notForAgent toast. #1396 handles both on the Rules card (CE-031): it writes the reason under the card and turns Fix off. Do the same here:
    • pass the Rules card's reason as runBlocked (_draft-editor.tsx:1276): agentFix.blocked, or notForAgent when openRulesForAgent(rules.rules).forAgent is empty;
    • disable Run Agent while it's set, and write it in the card's second line.

Checked and fine:

  • The PR is web only. It adds no route, server action, AI call or migration.
  • The agent's reason is rendered as text, and Compare still goes through cleanHtml.
  • fixRules now refuses to start while Start or Rewrite runs, or before the locked passages are read.
  • busy now covers the HTML view for a regular batch too, so Accept all can't write over it.
  • rulesAfter counts each open rule once, only rules open now, and is capped at the total.
  • Review skips page suggestions and accepted lines, and scrolls to the first open card in page order.
  • Every moving element has motion-reduce:animate-none or motion-reduce:hidden.
  • All keys used are in en.json, and the keys removed are no longer used.

Merge note: merge after #1394. This PR has no migration of its own. On main it hits only the conflicts it inherits from #1393 (content-writer.js, its test, schema.sql).

cihan-gyk and others added 10 commits October 23, 2026 14:45
# 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]>
A merge brought in a line formatted by another Prettier version; this puts
back main's formatting, so format:check passes.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Follow-up done in 8024168 (after merging #1394, which carries main):

  • The card's Run Agent writes its reason in the card's second line (amber, tied to the button with aria-describedby) instead of a title.
  • runBlocked is now agentFix.blocked, or notForAgent when the only open rules are ones the agent can't fix (One H1), so the button is off then too.
  • Test: the reason is in the card and the button has no hover-only title.

Web 2,926 tests + build, lint, typecheck, format pass.

@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk I merged main (#1404–#1410) forward through the content stack, bottom-up: #1393 → #1394 → … → #1403 → #1411 → #1412. Each PR is now mergeable again.

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.

Still approve.

The follow-up is done (8024168):

  • The card's Run Agent now writes its reason in the card, in amber, tied to the button by aria-describedby. It no longer uses a hover title.
  • The reason shows only when Run Agent does (runShown uses the same conditions as the two buttons).
  • The editor passes notForAgent when the only open rules are ones the agent doesn't fix, so the button is off in that case too (_draft-editor.tsx:781-786).

The merge commits add nothing of their own:

  • 76504fb's one conflict is the _page-rewrite import. It keeps only pageChangedSince, and nothing in the stack still uses the names it drops.
  • 9d1190b and c9df793 re-merge to the same tree.

The PR merges cleanly on current main.

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.

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).

@gkhngyk
gkhngyk merged commit 01a52a2 into ansvisor:main Oct 23, 2026
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 23, 2026
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