Repository navigation
feat(content): put brief and rules under one Instructions tab with a split Run Agent (CE-028–CE-031) - #1396
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]>
…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]>
|
@gkhngyk Content Editor v1.1, part 2 (CE-028–CE-031). This is web only and has no migration. Stacked on #1395 → #1394 → #1393 → #1387, so please merge it after them.
One gap, on purpose: the spec's "cited pages average 4,300 characters" needs the cited pages' lengths, and nothing reads those today. I'll bring it as its own small server PR after part 3, with no number made up meanwhile. If you'd rather it be measured somewhere specific (crawl at brief time vs. a nightly job), say so. Checks: lint (0 errors), typecheck, 2,926 web tests, format:check and build. I checked it in the browser at 1024 px in light and dark. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. One small follow-up:
- (low) ▾ can recommend a choice it has turned off. Take a page where the only open rules are ones the agent can't fix (One H1) and
rewriteAdviceis null. ▾ then shows the disabled Fix as "Recommended · 0 rules · small, reviewable changes" (_rules-tab.tsx:301,:187). Recommend nothing in that case:recommended={advice ? 'rewrite' : fixable > 0 ? 'fix' : null};- with
recommended: RunMode | null.
Checked and fine:
- The merge commit e212392 adds nothing of its own: re-merging its parents gives the same tree.
- The PR is web only. It adds no route, server action, AI call or migration.
- Brief's Run Agent is the existing rebuild, which holds AI budget on the server.
- Edit brief without a brief saves through
saveDraftBriefas before.EMPTY_BRIEFpassesdraftBriefSchemaand the column check. - Run Agent's choice:
- Fix is the default, and the button goes back to Fix once a rewrite starts;
- a page that is ready or published gets no rewrite;
- ▾ is closed while either run is going.
- The reason line is always mounted and gives the reason for the choice picked. Rewrite from brief writes its reason too.
decideFirstgetscountat all four call sites. All keys used are inen.json, and the keys removed are no longer used.- The header's rules chip, Sources' Rebuild with selection and Impact's lost prompts each open the right segment.
Merge note: merge after #1395. 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]>
…ions # Conflicts: # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
With only One H1 open and no rewrite advice, ▾ no longer shows the disabled Fix as Recommended. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd two lines A test from main still pressed "Apply rules with Agent", and two messages still named it; the button is Run Agent, its default Fix open rules. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk Follow-up done in 767032e: ▾ recommends nothing it has turned off. |
# Conflicts: # supabase/schema.sql
|
@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 (767032e). The ▾ menu recommends nothing when Fix is off and there's no rewrite advice:
recommended={advice ? 'rewrite' : fixable > 0 ? 'fix' : null}. The test checks that no item says "Recommended". - 85e964a renames the button in a test and in two messages (
too_long, the Length hint) to what it reads now. No UI string says "Apply rules with Agent" any more. - The merge commits add nothing of their own:
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).
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 2: Brief and Rules move under one Instructions tab. Each opens with a status card and one Run Agent, and Rules' two agent buttons become one split Run Agent ▾.
Panel (
_side-panel.tsx)Status card (
_run-card.tsx)sr-onlywhen nothing is in the way), so a screen reader announces the reason when it appears.Rules: one split Run Agent ▾ (CE-029)
rewriteAdvicesays so (Length more than 30% off, or ≥4 open rules), otherwise to Fix. The advice line stays under the card.Brief (CE-030)
wordsForLength).title.Toolbar
Copy
en.jsongetsrules.run.*,brief.status.*,panel.segments.*andeditor.run.about.Related issue
Content Editor v1.1 (Drive spec, updated 2026-10-23): CE-028, CE-029, CE-030, CE-031. 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 this in the browser on the dev DB with a temporary draft (deleted afterwards):
Tests:
_rules-tab.test.tsx:_brief-tab.test.tsx: both card states and their buttons, "Not set yet", Length in characters + words, the confirm under the card, no H2s yet, H2s added and saved without a brief, no confirm over an empty edited brief, and Rewrite from brief's written reason;page.test.tsx: the Instructions tab and its segments (order, badges, which opens), the header chip, Rebuild from Sources opening Brief, Run Agent / ▾ Rewrite page in the agent flows, and the counter's words;rules.test.ts:wordsForLength.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,919 tests) andyarn build.🤖 Generated with Claude Code