Skip to content

feat(content): send the rules in effect with Rebuild outline, so the brief plans to them with the brief rules (2026) on (brief rules PR 7) - #1541

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/brief-rules-send
Oct 26, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/brief-rules-send

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Brief rules 2026, PR 7 of 10: Rebuild outline sends the rules in effect. Web only, cut from main, no migration.

The brief rules (2026) plan a page to fit its rules, for example:

  • the answer length its "Answer under each H2" rule asks for;
  • the summary;
  • a dated point.

PR 4 (#1540) has the API read the rules from the rebuild request when CONTENT_BRIEF_RULES is on. They come in the request body as { brandId, sources, rules? }, the same shape as the writer's { sources, rules }. This PR sends them:

  • rulesForAgent (agent-write.ts) builds the list the Content Agent reads from the rules the editor checks. It keeps a rule only when it is:

    • on;
    • not one of the page feed's;
    • not one the editor handles itself (one H1).

    It keeps 60 rules at most, describes each as Fix does, and lists a fan-out rule's remaining fan-outs.

  • rulesForBrief is that list without the Keywords rule while it holds the current brief's own keywords. A rebuild writes the keywords anew from the sources, so planning to the old ones would hold it back. A Keywords rule the person set is sent.

  • The side panel keeps the rules as checked and describes them only when Rebuild outline asks (pageNow() → PageNow.rules), not on every keystroke.

  • useBriefRebuild passes them to the rebuildDraftBrief action as their own argument, beside the sources.

  • The action puts them in the request body only when there are any. RebuildSources stays as it is.

Order: before PR 4, the API reads the request body with a plain z.object, which drops rules. So this PR changes nothing until PR 4's server is deployed with the flag on, and the two can merge in either order.

Cost: about +200 input tokens per rebuild with the flag on, and nothing with it off.

Related issue

Roadmap CE-EVAL-001 / brief rules 2026 (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. Run the tests:
    cd web && yarn vitest run src/lib/content/agent-write.test.ts src/lib/actions/content-drafts-brief.test.ts "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-brief-rebuild.test.tsx"
  2. In the editor, open the browser's network tab and click Rebuild outline. The server action's request carries the rules in effect as its fourth argument, each with its name and aim.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Web checks, run locally on this branch:

  • yarn format: no changes beyond this PR's files.
  • yarn lint: 0 errors. The 6 warnings are in files this PR doesn't touch.
  • yarn typecheck: clean.
  • yarn test: 423 files, 3,959 passed.
  • yarn build: OK, with CI's placeholder env.

Tests:

  • rulesForAgent keeps the rules that are on and the agent's, and describes a fan-out rule with its status.
  • rulesForBrief leaves out the Keywords rule filled from the brief, and keeps one the person set.
  • A rebuild sends the rules in effect beside the sources, not inside them.
  • The action puts the rules in the request body only when there are any.
  • The editor page's rebuild passes the page's rules, without oneH1, feedMatch or the brief's own keywords.

Pre-push review

A review agent read the change before the push. Fixed from it:

  • Medium: the Keywords rule, filled from the current brief's keywords, would have had a rebuild plan around the old keywords. Now rulesForBrief leaves it out unless the person set it.
  • Low: the rules were described on every panel render, about 20–25 t() calls per keystroke. Now they're described only when a rebuild asks.
  • Low: the panel test now checks which rules are left out.

Left as is: after "Use lost prompts", a fan-out rule's "fan-outs to use" can be one read behind, because the rule statuses come from the editor's last render. The sources sent are current, and the next rebuild has them.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 26, 2026 13:26
…ld outline runs, so the brief plans to them with the brief rules (2026) on (brief rules PR 7)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the brief's own keywords, and describe the rules only when a rebuild asks for them (pre-push review)

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

@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, with follow-ups.

What I checked:

  • What the API does with rules.
    • Main, and the older API on prod: rebuildBody (server/src/routes/content-drafts.js:169) is a plain z.object (zod 4), unchanged since #1293. It drops a key it doesn't know, so the request passes as before and the brief is built as today.
    • #1540 (and #1543, which contains it) reads the field as rules: briefRules.optional(). Each rule is cut to 60 / 200 / 500 characters, and a request with more than 60 is refused. rebuildDraftBrief uses the rules only with CONTENT_BRIEF_RULES=true (planTo). With the flag off they're parsed and set aside, and the prompt and the guard stay as before.
    • So the server part this PR needs is #1540's route and prompt. Nothing it depends on is missing. PR 6 isn't open, and this PR doesn't need it.
  • What is sent.
    • The list is rules.rules, the one the Rules tab shows and Start, Rewrite from brief and Rewrite the page send. That's the draft's own choices, or My rules for its type on an untouched draft, over the page type's set with the brand's language.
    • It's filtered as agentWriteRequest filters: on, not the feed's, not one H1. Each rule is described by the same useRuleDescriber.
    • A fan-out rule names the fan-outs the page as written now doesn't use. Fix reads them the same way. Start reads a new page's against an empty page, but the rebuild also sends the page's headings as they are now, so reading the page as written fits it.
    • The Keywords rule is sent only when the person changed it. changed compares the rule's value with the brief's keywords, so a value the person typed is sent and the brief's own isn't. The tests cover both.
    • The person's own text rules aren't sent (item 1).
  • Size.
    • At most 60 rules: slice runs before map.
    • A name is a label. A detail is the rule's value (at most 500 characters by the rules schema) plus at most 300 characters of fan-outs.
    • In practice that's a few KB, far inside the server action's 1 MB and the API's limits.
    • #1540 cuts a long detail rather than refusing it, so nothing the editor describes can fail the rebuild there.
  • With the flag off.
    • There's no web flag. The web sends the rules whenever any are on, and the API decides what to do with them.
    • With CONTENT_BRIEF_RULES off, the person sees no change.
    • The rules are described only when a rebuild asks, so typing costs nothing.
  • Tests. Each fails without its change:
    • the hook test, because the fourth argument would be undefined;
    • the action test, because the body would have no rules, or rules: [] with a plain truthiness check;
    • the page test, because expect.any(Array) would get no fourth argument;
    • rulesForBrief, because the brief's own keywords would pass rulesForAgent.
  • Merge.
    • Web only, two commits on 4085418, no migration.
    • It merges cleanly on main (4efa150) and on #1543's head.
    • Since the base, main changed only content-drafts.ts, content-drafts-brief.test.ts and page.test.tsx among this PR's files. They merge without conflict, and the tests still read right: the action is mocked in the page test, and no test mocks agent-write where the side panel renders.
    • CI passes (format, lint, typecheck).
  • Before the API is deployed:
    • Rebuild outline, Rebuild with selection, Use lost prompts and Build brief work and read as today. The request carries the rules, and the API drops them.
    • Nothing that works today stops working.

Follow-ups:

  1. The person's own rules aren't sent (_side-panel.tsx:313-316, agent-write.ts:104).
    • Start, Rewrite from brief, Rewrite the page and Fix send the text rules that are on (textRules), and the writer lists them (content-writer.js:273).
    • The rebuild sends only the rule list. So with the flag on, the brief plans without a rule like "End each comparison with the trial offer", and the writer then follows a rule the plan left out.
    • Fix:
      • Send textRules beside rules, as startAgent builds them: rules.textRules.filter(({ rule }) => rule.on).map(({ rule }) => rule.text).
      • Have #1540's rebuildBody read them as writeDraftInput does (up to 50, 300 characters each), and list them under "Rules the page is written to".
      • Or say in the PR why the brief leaves them out.
    • The API on prod drops the field, so the two PRs can still merge in either order.
  2. One filter in two places (agent-write.ts:86-97 and :158-191).
    • agentWriteRequest repeats rulesForAgent's filter, its 60-rule cap and its description.
    • Fix: build the { rule, status } pairs there and call rulesForAgent. Then what the brief plans to and what the writer follows can't drift apart.

@gkhngyk
gkhngyk merged commit 062792e into ansvisor:main Oct 26, 2026
6 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