Skip to content

feat(content): name the brand, its products and competitors as written, and plan links to the pages listed only, in the brief behind CONTENT_BRIEF_RULES (brief rules PR 6) - #1545

Merged
gkhngyk merged 14 commits into
ansvisor:mainfrom
cihan-gyk:feature/brief-names-links
Oct 26, 2026

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Brief rules 2026, PR 6 of 10: the brief names things as they're written and plans its links.

What the rebuild reads, with the flag on

  • The brand's competitors, by name, from competitors; 20 at most. A failed read leaves none, as a failed read of the link targets does, and the rebuild goes on.
  • The pages it may link to, through readLinkTargets, as the Content Agent reads them:
    • the brand's own pages, the most cited and visited first;
    • the sources the draft keeps, without the brand's or competitors' sites and without the ones the person left out.

The prompt lists 12 of the brand's pages and 8 sources at most (BRIEF_LINK_PAGES). Those are also the only pages a link may go to. Each page's title is cut to 150 characters, and a page whose address is longer than the web keeps (2,048) isn't offered.

What the model is asked

  • products: the brand's products the page names, written exactly as the data writes them.
  • competitors: the competitors listed that the page names, as listed.
  • links.internal / links.outbound: up to 5 of the brand's pages and up to 3 sources. Each has its address copied from the list, the words to link, and the H2 it goes in.

What is kept (namesAndLinks)

  • entities.brand is the brand's name, from the database, never the model's.
  • entities.competitors keeps only names on the list, written as listed. A name off the list is dropped.
  • entities.products keeps a product only where the brand's own words write it: its name, industry and description, the page's title and headings, Your input, and its own pages' titles.
    • The spelling is taken from there (straight and curly apostrophes alike), so none is made up or respelled.
    • A name only a prompt, a search or a rule has ("ChatGPT", "FAQ") isn't the brand's.
    • The brand's or a competitor's name is dropped.
    • 10 at most.
  • links keep only addresses on the list, compared as links compare them (linkKey), and stored as listed:
  • The guard: competitor names are now given text, so it doesn't turn them into placeholders.
  • fitBrief: past 60,000 bytes, the links go first, then the fan-outs left out, the facts' sources, and the facts.

The eval

  • The judge sees a "Names as written" line and each link.
  • Three English cases now have competitors and pages to link to. They're fictional, as the brands are.
  • The judge is told which competitors and pages each case was given.
  • The URL gate counts those pages as given.

All of this is used with the flag on only, so the pinned version 1 hashes don't move.

Cost with the flag on

  • About +500 input tokens with 20 pages listed, and about +150 output tokens.
  • About +$0.0006 per brief at Gemini 3 Flash's list price.

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 server && npx vitest run src/lib/content-brief.test.js src/lib/content-brief-eval.test.js
  2. With an AI key and CONTENT_BRIEF_RULES=true, click Rebuild outline on a draft whose brand has competitors and Site pages. Check the saved brief:
    • entities.competitors are names on the brand's list;
    • entities.products are written as in the sources;
    • each links address is one of the brand's pages or a kept source.

Checklist

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

Server checks, run locally after the review fixes: format and lint clean; 223 test files, 2,801 passed, 3 skipped (the eval's recorded-baseline tests).

Tests:

  • Names:
    • competitors as listed, an unknown one dropped;
    • products as the brand's words write them (a heading, Your input, "C++"), once each;
    • none from a prompt or a rule, never the brand's or a competitor's name;
    • 10 at most;
    • an empty brand name;
    • a failed competitors read.
  • Links:
    • only pages listed, by address (a tracking parameter and a trailing slash still match), each once;
    • an off-list page and a source as an internal link are dropped;
    • anchors guarded, and a link whose words got a placeholder dropped;
    • 8 internal and 5 outbound at most;
    • 8 sources at most in the prompt, titles cut, an over-long address not offered;
    • a section the outline lacks reads as anywhere;
    • 12 of the brand's pages at most in the prompt.
  • The prompt: lists the competitors and both page lists.
  • Flag off: no competitors read and no readLinkTargets call.
  • fitBrief: the links go first when that's enough.
  • Contract test: every new limit compared with brief.ts.
  • Eval: the judge sees the names, the links and the competitors given; a page a case may link to passes the URL gate.

Pre-push review

A review agent read the change before the push. It confirmed:

  • the flag-off path is unchanged, and the pinned hashes pass;
  • the web contract holds;
  • fitBrief drops links first, and the fit test exercises that step;
  • the product match escapes special characters and stays fast: 180 ms for 300 failing names over 540,000 characters.

Fixed from it:

  • a product only a prompt or a rule names was kept;
  • the eval couldn't see names or links, and its URL gate would have flagged own-page links;
  • a failed competitors read stopped the rebuild;
  • titles weren't capped;
  • an over-long address could be offered;
  • a link with a placeholder was kept;
  • test gaps.

Left as is: Turkish İ/ı don't match across cases in the product check (iu), so such a product is dropped. That's safe: nothing wrong is kept.

🤖 Generated with Claude Code

cihan-gyk and others added 13 commits October 26, 2026 04:31
…ave as a placeholder, so the writer can't take it as given

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aceholder in half, and test the audience, names in headings and Turkish percentages (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s as a rubric, checks anyone can repeat with a gate on anything the brief wasn't given, a judge model's quoted scores, and a script that records them (CE-EVAL-001, brief rules PR 2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e by line; record the model's own answers and check them again in the test; read quotes in any marks, shortened, three words at least, in one line the judge saw; version the prompt under Quality's phase and the schema; keep a partial run apart; compare addresses by host and path (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ief behind CONTENT_BRIEF_RULES, with the data numbered, the page type's formats and the rules in effect; keep the facts' sources by kind and ref, cut to the web's version 2 limits and fit under 64 KB (brief rules PR 4)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…umber only the cited pages as sources, take the rules beside the sources, and read version 2's answers and facts in the brief eval (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…N schema only, so an off-list value never fails a charged call; take out only the page numbers given; match a fan-out as listed before its unquoted form; ask the judge for H2 lengths only (pre-push review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… its essentials, angle, the brand's own proof to gather, the fan-outs left for another page and freshness by page type, with Brief › Your input numbered as sources (brief rules PR 5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nt the eval's fan-out coverage over the fan-outs the brief keeps, and compare the input kind with the web's (pre-push review)

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

# Conflicts:
#	server/.env.example
#	server/src/lib/content-brief-eval.js
#	server/src/lib/content-brief-eval.test.js
#	server/src/lib/content-brief.js
#	server/src/lib/content-brief.test.js
#	server/src/scripts/eval-brief.js
…n, and plan links to the brand's pages and the sources listed only, in the brief behind CONTENT_BRIEF_RULES (brief rules PR 6)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… past a failed competitors read, cap the pages' titles and skip addresses the web can't keep, drop a link whose words got a placeholder, and give the eval cases competitors and pages to link to (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:

  • With CONTENT_BRIEF_RULES off.
    • Nothing new is read. The competitors and the link targets are Promise.resolve placeholders, so the rebuild makes the same queries as before.
    • The prompt is as before. linkable is an empty string, placed where nothing was, and the guard's given text is unchanged (competitors is []). The pinned hashes are untouched and hold this.
    • Version 1's schema has no products, competitors or links, so namesAndLinks never runs, and fitBrief returns a version 1 brief as it is. The output, the stored brief and the cost are the same.
  • The new reads, with the flag on.
    • The competitors are read by brand_id on its index. The brand is the draft's, checked just before the reads.
    • readLinkTargets makes the reads the agent and the writer already make on every run:
      • the brand's site pages (the top 41);
      • the Sources tab's content_draft_sources for the draft (bounded in 00226);
      • the draft's source choices.
    • All of them run beside the brand read, before the budget hold. A slow read delays the call but charges nothing.
    • A failed read leaves its list empty and is logged. supabase-js returns a network failure as an error, so neither read fails the rebuild.
  • Links.
    • A link is kept only when its address, read by linkKey, is on the list it was offered: internal links against the brand's pages, outbound links against the sources. It's stored as listed: http(s) only (readLinkTargets keeps nothing else), and at most 2,048 characters, since linkable filters before the cut.
    • The sources leave out the brand's and the competitors' sites and the ones the person left out. The brand's pages leave out the draft's live page.
    • The link words go through the guard and are cut to 120, and a link whose words have a placeholder is dropped. The section is an outline H2 or null.
    • At most 8 internal and 5 outbound links; links is null when there are none.
  • Names.
    • The brand's name comes from the database, cut to 120.
    • A competitor is kept only when it's on the list, and is stored as listed.
    • A product is at most 120 characters. It must be found, as a whole word, in the brand's own words, and it's taken as written there. It's never the brand's or a competitor's name.
    • At most 10 of each list.
    • This checks the spelling, not that the name is a product: a common word in the brand's text ("pricing") passes. That's fine for a plan.
  • The stored brief and the editor.
    • Each field is written the way draftBriefSchema on main reads it:
      • entities: a brand of at most 120 characters, and at most 10 products and 10 competitors of at most 120 each;
      • links: at most 8 internal and 5 outbound, each with an http(s) url of at most 2,048, an anchor of at most 120, and a section of at most 300 or null.
    • The contract test compares every new limit with brief.ts.
    • Edit brief keeps both fields (...brief). The Brief tab doesn't show them yet.
    • A brief stored before has neither field and reads as it did (.nullish().catch(null)).
  • The work.
    • The product match escapes the name and runs one regex per name over the brand's own words. That's linear for each name, and the PR's timing (300 names over 540,000 characters in 180 ms) goes well past any real brief.
    • The guard reads a link's words as it reads every other field, and the placeholder check runs on at most 120 characters.
  • The fit. The links go first. The new test fails without that step.
    • entities isn't cut (2,520 characters at most). That adds a little to #1540's note on a brief at every limit, but it's still far from a real brief.
  • The AI budget. Still one call. With the flag on, the extra tokens are charged by what the call used. A missing new key fails the call as in #1540: it's charged and nothing is saved.
  • Merge.
    • Through a temp base with main's tree and both parents (1851425 and main), the merge is clean.
    • The merged tree differs from main by exactly this PR's diff (5 files), and main's copies of those files are 1851425's.
    • Server only, no migration. Nothing changes on Vercel at merge, or at the API deploy while the flag is off.

Round 32's open items:

  • The judge can't quote a one-word line (#1540 item 1): not fixed, and now worse. See item 2.
  • Fan-out coverage counts only the kept fan-outs (#1543 item 1): not touched.
  • A fact's source ref isn't checked to be http(s) (#1540 item 3): not touched. The new link addresses are http(s) by construction, so the gap is still in fact sources only.
  • The judge's rubric isn't versioned (#1540 item 2): this PR changes the judge's prompt again. No record exists yet, so nothing goes stale now.

Follow-ups (before PR 10 compares version 2 with the baseline):

  1. The judge and the gate are told a version 1 brief was given what it wasn't (server/src/lib/content-brief-eval.js:194-201, :266).
    • In the three cases with competitors and pages, buildBriefPrompt lists them only with the rules on. But buildJudgePrompt always says "Competitors it was given", and briefChecks always counts those pages as given addresses.
    • So the version 1 baseline is graded under entities against names it never saw, and its gate passes a guessed own-page address. Both skew the comparison PR 10 makes.
    • The judge also isn't told the sources an outbound link may go to, which the links criterion asks about.
    • Fix:
      • Show and count the competitors and the link targets only for a brief built with them (brief.version === 2).
      • List the sources to link to beside the brand's pages.
      • Add a test: a version 1 brief's judge prompt for such a case has no "Competitors it was given".
  2. The judge can't quote the new "Names as written" line (content-brief-eval.js:148, :309).
    • 27 of the 30 cases have no competitors. Unless the page names a product, their line is just the brand's name: one or two words.
    • The quote check asks for three words, read without the label, so a quote of that line ("Names as written: Ledgerly", or "Ledgerly") scores 0 under entities and is marked unquoted.
    • This is #1540 item 1 again, now on a second criterion. The link lines have the label half of it.
    • Fix: the same as #1540 item 1: read a quote against the line with its label, and let a quote of a whole line pass under three words.
  3. The brief plans links the rules have turned off (server/src/lib/content-brief.js:166, :379).
    • readLinkTargets is always asked for both lists. The writer asks by the rules in effect (content-writer.js:558).
    • So with Internal links off for the draft, the brief still lists the brand's pages and plans links to them, which the writer can't keep.
    • Fix:
      • When rules are sent, pass their keys (new Set(planTo.map((r) => r.key))), as the writer does. With none sent, keep both lists.
      • Add a test: rules without internalLinks give no brand pages in the prompt and no links.internal.
  4. Bound the competitor names in the prompt (content-brief.js:376-394, :972).
    • competitors.name has no length limit in the table or the action, and a name is only trimmed. Its full length and any line breaks go into the prompt.
    • The names are joined with ", ", so "Acme, Inc." reads as two names, and the model's "Acme" is then dropped because it isn't on the list.
    • The read has no order, so which 20 of a longer list are given can change from run to run.
    • Fix:
      • Collapse the whitespace in each name and cut it to 120 (a longer name can't be stored anyway).
      • Order the read by created_at, as the Competitors list shows them.
      • List the names one per line (list(competitors)), or each in quotes.
      • Put the page titles in quotes too, with double quotes made single, as the input items are: a cited page's title is that site's own text.
  5. The brand's page titles are its words for products, but not for the guard (content-brief.js:640, :752, :887-900).
    • Products may come from the brand's page titles, but briefKnown doesn't list those titles.
    • So a link whose words repeat its page's title ("Top 10 espresso grinders") gets "[figure, source]" and is dropped. And when a product is named only in a title, an H2 that names it reads "Grinder [figure, source]", while entities.products keeps "Grinder 900".
    • Fix:
      • Add the brand's listed page titles to the guard's given text, as the competitors now are.
      • For a source, guard its link's words with its own title known.

As with #1543's item 4, nothing reads entities or links yet: not the writer's briefText, and not the Brief tab. A later PR in the series should, before the flag goes on.

@gkhngyk
gkhngyk merged commit dfa51a0 into ansvisor:main Oct 26, 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