Skip to content

feat(content): read and keep the brief's version 2 through Edit brief (brief rules PR 3) - #1539

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

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/brief-schema-v2

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Brief rules 2026, PR 3 of 10: the editor reads and keeps the brief's version 2. Web only, cut from main, no migration.

The server's brief gains the 2026 rules in PR 4–6, behind CONTENT_BRIEF_RULES. That brief must still read in the editor, and Edit brief must not drop what it doesn't show. Two things stand in the way today:

  • draftBriefSchema is a plain z.object, which drops any field it doesn't know;
  • Edit brief rebuilt each section from its four fields.

So this PR ships first, and only reads and keeps the new fields. The Brief tab shows them in PR 9.

  • web/src/lib/content/brief.ts: version 2's fields, each optional, so a brief from before them reads as it was.
    • Per section:
      • answer: a note on what the section's first, direct answer must say;
      • format: paragraphs, list, steps, table or faq (a "faq" section's key points are its questions);
      • facts: up to 4, each a claim, the kind of source it needs (statistic, study, quote, example, official) and the source it was given. The source is kept by kind and ref, with its name, as a suggestion keeps its own (00248), never by its number in one run (S1…), which changes as Sources change.
    • Per page:
      • version: 2, tldr, angle;
      • proof: the brand's own proof to gather, as Your input takes it (experience, data, a case, a test, a quote). Whether Your input has it is read from Your input when shown, not stored: it changes after a rebuild;
      • leftOut: fan-outs kept for another page;
      • freshness: a dated point, an "Updated" line, the year in the title;
      • entities: the brand, its products and the competitors, as written;
      • links: internal up to 8, outbound up to 5, http(s) addresses only.
    • BRIEF_V2_LIMITS holds the limits.
  • Read tolerantly, so a newer server can't hide a brief here:
    • an unknown format or a later version reads as none;
    • an item of an unknown kind, or a link that isn't http(s), is left out;
    • lists are kept to their limit and long version 2 text is cut.
    • Version 1's fields stay as strict as before. The comment says a new value ships here first.
  • getDraftBrief: a brief of the draft's own that can't be read is said as a failed read. It no longer falls back to the opportunity's brief or none, so Edit brief, which shows on a read brief only, can't write over it.
  • saveDraftBrief: a brief past the column's 64 KB (00212) is refused as too_long before writing, and Edit brief says so.
  • __fixtures__/brief-v2.json: a sample version 2 brief. PR 4's server test reads this same file, and the limits and kinds from brief.ts, as content-page-types.test.js reads the web's files. There's no copy to drift.
  • _brief-tab.tsx: Edit brief keeps each section's other fields (...section), and with ...brief the page's too, as before.

The contract is written into the plan for PR 4–6.

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. cd web && yarn vitest run src/lib/content/brief.test.ts "src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_brief-tab.test.tsx".
  2. Nothing changes on screen. A brief saved with the new fields, for example the sample's JSON put in content_drafts.brief on a dev database, opens in the Brief tab, and Edit brief → Save brief keeps them.

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 files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Web: yarn test (3,964 passed) and yarn build.

Tests:

  • the sample reads back whole;
  • a brief from before reads as it was;
  • a newer server's values (a later version, an unknown format, an unknown kind, too many facts, long text) read without hiding the brief;
  • only http(s) links are kept;
  • getDraftBrief reads version 2 and says an unreadable brief of the draft's own as a failed read;
  • saveDraftBrief keeps version 2 as the person's, and refuses past 64 KB;
  • Edit brief keeps a section's answer, format and facts and the page's plan, and says too_long.

A pre-push review ran; its findings are in the second commit (tolerant reading, kept sources, http(s) links, the 64 KB check, proof without have, nullish text).

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 26, 2026 12:24
…d facts per section; TL;DR, angle, proof, fan-outs left out, freshness, names and links per page), and keep them through Edit brief (brief rules PR 3)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…kind and ref, keep http(s) links only, refuse a brief past 64 KB, and never let Edit write over a brief it can't read (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 to fix before PR 4 writes version 2.

What I checked:

  • Today's briefs.
    • Version 1's rules are unchanged; the diff only adds fields.
    • Every version 2 field is optional both ways: absent when read, absent when saved. In zod 4.4, preprocess and catch count as optional for an absent key, and an absent optional key stays out of the result.
    • So a version 1 brief reads as the same object, and Edit brief writes the same JSON as before. The tests check version and facts stay undefined.
    • Only two things write content_drafts.brief on main: the server's rebuild and Edit brief. The rebuild cuts to the version 1 limits (BRIEF_LIMITS, mapOutline). citedLength stays within its range (at most 500,000 characters and 5 pages).
    • So no stored brief should start failing to read under the new getDraftBrief.
  • Edit brief.
    • ({ points, ...s }) keeps a section's answer, format and facts, and leaves out the editor's own points. heading and keyPoints are replaced as before.
    • ...brief keeps the page-level fields. New sections are as before.
    • These fields stay with their section when its heading is rewritten, as fanout and platform do. Nothing shows them until PR 9, so keep CONTENT_BRIEF_RULES off until then.
  • Not trusted.
    • saveDraftBrief parses what the browser sends again, with the same kinds and limits, so a changed request gets no further than the editor's own read.
    • Keys the schema doesn't know are still dropped on read and on save. A later version saves as none. That's fine while the web ships first: it goes out on merge, and the API is deployed by hand later.
  • Nothing rendered unsafely.
    • Nothing new renders in this PR. Links are http(s) only (z.url({ protocol })), and javascript: and ftp: are dropped, with tests.
    • A fact's source ref isn't checked as an address. Today the suggestion chips never use a ref as a link. PR 9 should keep it that way, or check http(s) first.
    • getDraftBrief logs zod's issues, which leave the input out, so no brief text goes to the logs.
  • Size. too_long is checked with jsonbBytes, which measures text the way Postgres writes jsonb. That's what 00212's octet_length(brief::text) <= 65536 checks. It runs before the write, and the test checks nothing is written.
  • A brief of the draft's own that can't be read is now a failed read. It no longer falls back to the opportunity's brief, so Edit brief can't write over it.
  • Merge state. Built on 4085418, no migration. It merges cleanly on main as it is now (38ca76b, with #1514–#1519). None of those touches the brief. CI passes; its web job runs format, lint and typecheck only.
  • Before the API is deployed:
    • Nothing writes version 2 yet.
    • A version 1 brief reads, shows and saves as today.
    • A brief past 64 KB is refused before the write, with the same toast as today (item 1).
    • Nothing that works today stops working.

Low, follow-up (please fix before PR 4 writes version 2):

  1. _brief-tab.tsx:389 and content-drafts.ts:2155:
    • In a production build, an error thrown from a server action reaches the browser with React's generic message and a digest, not too_long.
    • So on prod the person still sees "Couldn't save the brief. Try again.", and trying again can't help. The test passes only because it mocks the action.
    • Fix: check the size in Edit brief before calling, as _use-draft-rules.ts:237 does with draftRulesFit (jsonbBytes runs in the browser too), and keep the server's check as the guard. Or return { error: 'too_long' } from the action, as rebuildDraftBrief does.
  2. brief.ts:196-197:
    • A fact's source label is held to 300 characters, through claim's limit, and BRIEF_V2_LIMITS has no key of its own for it. The PR says a fact keeps its source as a suggestion does.
    • A suggestion's label is a prompt's text (up to 500 characters) or a cited page's address (up to 2,048) (server/src/lib/content-sources.js:67, :74).
    • Such a fact fails as a whole, so it's left out on read, and the next Edit brief saves the brief without it.
    • The same holds inside every list item: a long claim, proof, left-out query, name, anchor or link section drops its item, while top-level text is cut.
    • Fix: give the source its own limits in BRIEF_V2_LIMITS (sourceRef, sourceLabel), so PR 4's test reads them. Cut text inside items as v2text does, so length never drops an item.
  3. brief.ts:149-163:
    • These still fail the whole brief: facts: null, proof: null or leftOut: null, or an answer, tldr or angle that isn't a string.
    • With this PR's getDraftBrief, that's a failed read with only Retry (_brief-tab.tsx:98): no Edit brief and no Rebuild, so the person can't get past it.
    • Fix: read null as none, and add .catch(undefined) to v2text and v2list, so only version 1's fields can fail the read. A test with { ...v2, proof: null } and a section with facts: null would hold it.
  4. For PR 4, the limits add up to far more than the column holds:
    • Version 1 at its limits is about 60 KB of ASCII.
    • Version 2's per-field limits allow roughly 180 KB more. Four facts per section with 2,048-character refs come to about 130 KB on their own.
    • Edit brief is guarded now; the rebuild's write isn't. A brief past 64 KB fails 00212's check after the model call has been charged.
    • Fix: trim the brief to fit (jsonbBytes ≤ 65,536, for example dropping facts and links from the end) before the write.

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