Repository navigation
feat(content): show the Content Agent as a card over the page (CE-025, CE-026) - #1395
Conversation
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]>
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]>
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]>
|
@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). |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. One small follow-up:
- (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 thenotForAgenttoast. #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, ornotForAgentwhenopenRulesForAgent(rules.rules).forAgentis empty; - disable Run Agent while it's set, and write it in the card's second line.
- pass the Rules card's reason as
Checked and fine:
- The PR is web only. It adds no route, server action, AI call or migration.
- The agent's
reasonis rendered as text, and Compare still goes throughcleanHtml. fixRulesnow refuses to start while Start or Rewrite runs, or before the locked passages are read.busynow covers the HTML view for a regular batch too, so Accept all can't write over it.rulesAftercounts 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-noneormotion-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).
# 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]>
|
@gkhngyk Follow-up done in 8024168 (after merging #1394, which carries main):
Web 2,926 tests + build, lint, typecheck, format pass. |
|
@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
left a comment
There was a problem hiding this comment.
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 hovertitle. - The reason shows only when Run Agent does (
runShownuses the same conditions as the two buttons). - The editor passes
notForAgentwhen 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-rewriteimport. It keeps onlypageChangedSince, 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
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
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.
The card (
_agent-card.tsx), above the toolbar, replaces the agent row and the rewrite bar. It has three states:The gain (
rulesAfter) counts each open rule an open suggestion says it meets, once.Motion (CE-026). The tile:
The keyframes are
--animate-agent-*inglobals.css. Every moving element also hasmotion-reduce:animate-none(orhidden), so reduced motion stops all of it.Layout.
bg-muted,border), so light and dark follow the app. The tile isbg-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.tsxis removed;PageCompareDialog;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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
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
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(2,916 tests) andyarn build.🤖 Generated with Claude Code