Skip to content

feat(content): put brief and rules under one Instructions tab with a split Run Agent (CE-028–CE-031) - #1396

Merged
gkhngyk merged 32 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-instructions
Oct 23, 2026
Merged

gkhngyk merged 32 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-instructions

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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

Stacked on #1395 (the agent card), which is stacked on #1394 → #1393 → #1387. Merge after them.

Spec: Drive › Content Editor › CONTENT-EDITOR-v1.1-spec.md §3 and §4, and the mockup CONTENT-EDITOR-v1.1-mockup.html. Both were updated on 2026-10-23 with the Length in characters + words.

Covers CE-028, CE-029, CE-030 and CE-031. Still to come:

  • part 3: the data the agent uses;
  • part 4: progress steps and Stop (server);
  • part 5: "Based on" chips.

Panel (_side-panel.tsx)

  • The tabs are Instructions · Sources · Live page. "Plan" is not used, so it doesn't clash with Content › Plan.
  • Instructions holds a Brief | Rules control, Brief first. The panel opens on Rules, as it did before.
  • The rules still open show on the tab (amber count) and on the segment ("8 open").
  • The Brief | Rules segments switch with the arrow keys, with one tab stop. The tab's count is read out as "8 rules open".
  • The header's rules chip opens Rules. Rebuilding the brief from Sources opens Brief. The closed panel's rail lists the three tabs.

Status card (_run-card.tsx)

  • Each segment starts with a card: a status line on the left, the button, then an ⓘ.
  • The ⓘ tip opens below the icon, so the panel's edge never cuts it.
  • When the agent can't run, the reason is written under the card in amber ("Review the open suggestions first, then run the agent."). It is no longer only a hover title.
  • The reason line is always mounted (empty and sr-only when nothing is in the way), so a screen reader announces the reason when it appears.

Rules: one split Run Agent ▾ (CE-029)

  • Card: "8 rules are not met", plus the first three rule names.
  • Run Agent runs the safe default: fix the open rules.
  • ▾ offers:
    • Fix open rules: N rules · small, reviewable changes · Less AI usage;
    • Rewrite the whole page: every rule in "{set}" · one new version, cited passages kept · More AI usage.
  • "Recommended" goes to the rewrite when feat(content): rewrite the page to its rules from the Rules tab, and compare it #1394's rewriteAdvice says so (Length more than 30% off, or ≥4 open rules), otherwise to Fix. The advice line stays under the card.
  • The two choices are menu radio items, so a screen reader hears which one is picked.
  • Picking the rewrite renames the button Rewrite page, so it says what will run.
  • Once a rewrite starts, the button goes back to the safe default, so the next one-click run is never the costly one by accident.
  • The choice is worked out once. A page ready or published offers no rewrite, so the choice falls back to Fix.
  • When only rules the agent can't fix are open (One H1), Fix is disabled in ▾, and the reason under the card says what to do instead. The rewrite stays available.
  • On a page that is ready or published there's no rewrite, so the button is plain, and its ⓘ tip doesn't mention ▾.
  • "Less / More AI usage" stays until there's a real per-run estimate. No credit numbers are made up.

Brief (CE-030)

  • Card:
    • empty: "No brief yet · Goal, audience and outline are empty." with Run Agent (black);
    • filled: "Brief ready · 2 H2s" with Rebuild brief (secondary).
  • An edited brief still asks before it's rebuilt, but not while it's empty. The question now sits right under the card, not past the outline.
  • A brief with a goal but no H2s yet reads "No H2s yet. Rebuild brief to draft them, or add H2s yourself."
  • Empty fields say "Not set yet" instead of "—".
  • Length comes in characters first, then about as many words: "3,000 characters · ~500 words", with "From the rules" under it.
    • Words are characters ÷ 6, to the nearest ten (wordsForLength).
    • Characters stay the unit rules count in.
  • The outline says "Empty. Run Agent to draft one, or add H2s yourself."
  • Edit brief is there without a brief too, so H2s can be added by hand.
  • The bottom Build / Rebuild button is gone; the card has it.
  • Why Rewrite from brief waits is written under it too, no longer only in its title.
  • The spec's second line, "cited pages average 4,300 characters", needs the cited pages' lengths. Nothing reads those today. It comes in a later part with a server read, rather than a number made up here.

Toolbar

  • The counter adds the page's words: "147 / 3,000 characters · 24 words" ("1 word" on a one-word page).

Copy

  • en.json gets rules.run.*, brief.status.*, panel.segments.* and editor.run.about.
  • The two old rule buttons' copy and "Build brief" are removed.
  • "Rebuild outline" now reads "Rebuild brief" throughout.

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 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. The panel opens on Instructions › Rules. The tab shows the open rules' count, and the Rules segment shows "N open".
  2. The Rules card reads "N rules are not met", plus the first rule names.
    • Run Agent fixes the open rules.
    • ▾ › Rewrite the whole page renames it Rewrite page, and it rewrites.
  3. With a suggestion open, Run Agent is disabled, and the reason is under the card in amber.
  4. Hover the ⓘ. The tip opens below it.
  5. Brief:
    • with no brief, "No brief yet" and a black Run Agent; with one, "Brief ready · N H2s" and Rebuild brief;
    • Goal and Audience read "Not set yet";
    • Length reads "3,000 characters · ~500 words / From the rules".
  6. The toolbar's counter adds the words.

I checked this in the browser on the dev DB with a temporary draft (deleted afterwards):

  • at 1024 px wide with the panel open, the card's text, split button and ⓘ stay inside the card;
  • the ▾ menu and the ⓘ tip open below and fit the window;
  • the dark theme's badges, amber reason and primary button.

Tests:

  • _rules-tab.test.tsx:
    • the card, then the split button and the ⓘ;
    • Run Agent fixes;
    • the ▾ radio items (Fix checked) with "Recommended";
    • picking the rewrite renames and runs it, then Fix is back;
    • the reason under the card for the choice picked;
    • working, with ▾ disabled;
    • only One H1 open;
    • all rules met;
    • plain Run Agent without a rewrite;
  • _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

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

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Collaborator Author

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

  • The panel's tabs become Instructions · Sources · Live page. Instructions holds Brief | Rules.
  • Each segment opens with a status card. Rules has one split Run Agent ▾ (Fix open rules / Rewrite the whole page) in place of feat(content): rewrite the page to its rules from the Rules tab, and compare it #1394's two buttons. Brief has Run Agent / Rebuild brief.
  • Why the agent waits is written under the card, not only shown on hover.
  • Length shows characters and about as many words, and the toolbar counter adds words.

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.

@cihan-gyk cihan-gyk changed the title feat(content): put brief and rules under one Instructions tab with a split Run Agent feat(content): put brief and rules under one Instructions tab with a split Run Agent (CE-028–CE-031) 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) ▾ 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 rewriteAdvice is 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 saveDraftBrief as before. EMPTY_BRIEF passes draftBriefSchema and 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.
  • decideFirst gets count at all four call sites. All keys used are in en.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).

cihan-gyk and others added 7 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]>
cihan-gyk and others added 5 commits October 23, 2026 15:01
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]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Follow-up done in 767032e: ▾ recommends nothing it has turned off. recommended is advice ? 'rewrite' : fixable > 0 ? 'fix' : null (RunMode | null); the One-H1-only test checks no item says Recommended. Also 85e964a: a test that came in from main (#1373) still pressed "Apply rules with Agent", and two messages still named it; they now say Run Agent / Fix open rules.

@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 (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:
    • 5cd7c0c's one conflict is the imports in _draft-editor.tsx. It keeps PanelTarget and the one _page-rewrite import.
    • 88ada48 re-merges 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).

@github-actions github-actions Bot removed 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.

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 c9a9bbc into ansvisor:main Oct 23, 2026
4 of 5 checks passed
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