Repository navigation
feat(content): show the data the Content Agent writes from (CE-032, CE-034) - #1397
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]>
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]>
|
@gkhngyk Content Editor v1.1 part 3 (CE-032, CE-034). Web only, no migration. Stacked on #1396 → #1395 → #1394 → #1393 → #1387.
Known gap: today Fix open rules doesn't read the prompts, fan-outs or Search Console queries. It reads cited pages only for link rules. The spec has it read them all ("Reading 20 cited pages → Matching 21 fan-outs → …"). That's the next server PR, together with the "Based on" chips (CE-033), so the line becomes exact for Fix as well. PR titles now carry their task IDs (#1395 CE-025/026, #1396 CE-028–031), as the product brief asks. Checks: lint (0 errors), typecheck, 2,935 web tests, format:check, build. Browser-checked at 1024 px in light and dark. |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good.
Merge note: "Uses your data" under Rules' Run Agent (_side-panel.tsx:307) says Fix open rules writes from the kept sources. That's only true once #1398 takes sources on Fix and #1399 sends them. "Last used by Content Agent" also counts a Fix batch (_side-panel.tsx:179). Merge #1397–#1399 together, so the line is never shown on its own.
Checked and fine:
- The note's flag is only in the user's own
user_metadata:auth.usershas no update trigger;- nothing that grants access reads the key;
- the dashboard layout reads the user with
getUser(), so the flag holds after a reload and on another device.
- There are no new reads.
created_atwas already selected, and one batch is one insert, sosuggestions[0].createdAtis the batch's time. - The counts come from the same
buildSourceGroups/includedCountsthe Sources tab uses, so unchecking a source lowers both. - "Last used" skips a failed run and values that aren't dates.
- The tab's count is read out through
sr-only. - Every string is in
en.json, and the tests cover the line, the note, the tab andcreatedAt.
# 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]>
# 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 PR has no new commits of its own, only three merges of #1396's branch (8a293fe, 82ab17f, 339790c). Each one re-merges to the same tree.
- The PR merges cleanly on current main.
The merge note still applies. The "Uses your data" line under Run Agent describes behaviour that #1398 and #1399 add, so merge #1397–#1399 together.
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 3: the editor shows which of the person's data the Content Agent writes from: under each Run Agent card, on the Sources tab, and in a first-visit note.
Under each Run Agent card (CE-032)
buildSourceGroups+includedCounts, on the editor's one shared read. Unchecking a source there lowers the count at once.Sources tab (CE-034)
agent_state_at: Start with Agent, Rewrite from brief on a new page, which leave no suggestions).DraftSuggestiongains an optionalcreatedAt, read ingetDraftSuggestions.First-visit note (CE-032)
user_metadata(content_agent_data_note_dismissed), so it never shows again on any device. There's no migration.localStorage(per browser).updateUser({ data })merges keys, sofull_namestays. Nothing authoritative reads this key.Not in this part
Related issue
Content Editor v1.1 (Drive spec, 2026-10-23): CE-032, CE-034. 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 at 1024 px, in light and dark:
Tests:
_data-note.test.tsx:_sources-tab.test.tsx: "Last used by Content Agent" (never / 2 minutes ago / just now) and "N sources in use";page.test.tsx:content-drafts.test.ts: a suggestion is read with itscreatedAt.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 testandyarn build.🤖 Generated with Claude Code