feat(cms): fill a site's editorial brand context from its own blocks - #6341
Open
aka-sacci-ccr wants to merge 13 commits into
Open
feat(cms): fill a site's editorial brand context from its own blocks#6341aka-sacci-ccr wants to merge 13 commits into
aka-sacci-ccr wants to merge 13 commits into
Conversation
Adds an "Autonomous content" collection to the Content tab, holding the brand context every generated blogpost will be written against: tone of voice, generation dos and don'ts, audience, values, blog categories, competitors. Persists to the site's own `.deco/blocks/blog-manager-brand.json` as plain JSON — no new table. Same path and field names Spire writes, so a site it already set up opens here populated. `BLOG_BRAND_EXTRACT` fills the empty fields by reading the site's own CMS blocks. No scraper and no new credential: the blocks are already in the browser's decofile, and the inference runs on the org's own `smart` tier via `resolveTier`, so it bills to the org rather than to an instance-wide key. Two things the real data forced: - Serialized block size is a bad proxy for prose. Farm Rio's "Sobre Farm" page is 15KB of JSON carrying two sentences, and ranking its 1018 pages by size surfaced product-listing stubs while burying the institutional pages that hold the brand's values. `extractBlockProse` walks a block and keeps only `prop: phrase` lines, deduped. - That site has 1018 pages and zero posts, so "read the existing posts" cannot be the only path. The tiers degrade: posts, then categories, then pages. Re-running the extract only writes into fields that are still empty, so it can never wipe dos/don'ts someone wrote by hand. Testing: 62 unit tests in `blog-data.test.ts` cover the prose walker and the evidence ranking (tier order, prose-density ordering, char budget, empty site, missing page keys). The `25` failures in `bun test apps/api/src/tools/` are pre-existing — same count on a clean tree, and each file passes in isolation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The brand context was ten fields in one column, four of them `string[]`. That
shape didn't hold up:
- A rule worth writing down doesn't fit one line. "Never print prices in a text
block, use ProductCard" is a short name plus an explanation, and both were
fighting over the same 36px input.
- A competitor's name alone says nothing about why it matters or how the brand
differs from it — which is exactly what a generated post needs to know.
- Identity data, generation instructions and guardrails are read at different
moments by different people, with no hierarchy separating them.
So `dos`, `avoid`, `values` and `competitors` become `Array<{name, value}>`,
where `value` renders in the markdown editor already used by the task dialog.
`categories` stays `string[]` — it's a taxonomy, not a rule, so it has no body.
No migration. `normalizeBrandRules` reads both shapes: a legacy flat string
becomes the rule's name with an empty body, so a block Spire wrote opens intact
and picks up the new shape on its next save.
Four tabs — Basics, Generation rules, Guardrails, Extra context. The "read this
site's content" card stays outside them, since it fills fields across all four.
`MarkdownEditor` reads `defaultValue` only on mount, so an extract that filled a
rule body would have left the old text on screen. An `editorRevision` counter
keys the editors and remounts them onto the new values.
Competitors now come from web search, because a site's own blocks structurally
cannot answer that one — a brand doesn't name rivals in its own copy. It runs
only when the blocks named none, on the org's own `web_search` tier via
`tryResolveTier`, and returns `[]` when the org has no such tier, when the
search finds nothing, or on any error: this enriches the result and must never
be what makes the extract fail. Scope is deliberately competitors-only; letting
search rewrite `tone` or `values` would trade the brand's own prose for a third
party's summary, which the prompt already forbids.
No import from the chat harness: `mode: "quick"` of the research hook reduces to
a call against the search-capable model, so this does that directly rather than
inventing a `taskId`/`toolCallId` for a durable job it doesn't need.
Testing: 6 new unit tests for `normalizeBrandRules` (legacy string, well-formed
rule, half-migrated mixed list, body-only rule, entries with no text, non-array).
217 pass across the content suite. `tsc` clean in both workspaces, `knip` clean,
`lint` 0 errors. Also drops `dosLabel`/`dontsLabel`, orphaned by the tab titles.
Not yet exercised against a live model: the editor remount, and whether this org
has a `web_search` tier at all.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Nests the three screens behind the single "Autonomous content" collection row instead of promoting them to siblings of Posts and Authors in the Content sidebar. Planner and Ideas ship as placeholders that say what will land there; the inner rail is what makes room for them without touching navigation again. Library keeps the brand context, now under Content-OS-style underlined tabs (Context / Formats) with a fixed four-item rail: basics, generation rules, guardrails, extra context. The rail is sticky, so it stays put while a long guardrail list scrolls. The rule lists were a column of stacked markdown editors, which is unreadable past two rules. Now a row shows the rule's name and clicking it opens that rule's body, one at a time. Deleting a rule closes the editor when the indices below it shift, so the wrong rule can't end up open. `MarkdownEditor` grows an `attachments` prop, off for these fields: a brand guardrail is text, and the picker plus the paste/drop upload handlers were offering an image flow that has no meaning here. The extract button says "Fill" rather than describing its mechanism, and while it runs a status line names the step: reading the site, inferring the voice, searching for competitors. Those are the pipeline's real phases but timed on the client — the tool is one round trip, so the client cannot know the server's step. That's also why there's no progress bar: the design system's `Progress` is determinate, and any percentage here would be invented. Both prompts now pin the output language to the site's own. A Portuguese site was getting an English profile, which is unusable twice over: the people who maintain it work in that language, and the model that later reads it copies the language it sees. Fixed one instance of the same bug inside the prompt, where an English example illustrated Portuguese output. Also translates the pt-BR entries left in English (library, planner) and drops the `useT` briefly added to `content-browser`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rebasing onto main landed this branch on a tree where `use-blog-mutations.ts` no longer exists — #6271 deleted it after blog writes started 404'ing, folding the key-to-file mapping into the server. Git replayed the commits cleanly because the import target was simply absent rather than conflicting, so only `tsc` caught it. `useSaveBlock` is the replacement and no longer takes `packagePath`; it resolves that itself. The `blog-manager-brand` key has no slashes, which is the only reason `use-blog-mutations` existed separately, so there is nothing else to port. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
aka-sacci-ccr
force-pushed
the
blogpost-generation-cms
branch
from
August 20, 2026 21:01
a153839 to
22104fe
Compare
Replaces the "Ideias" placeholder in Conteúdo autônomo with Temas, the first step of the generation flow (Temas -> draft -> format -> post). A theme is a title plus a markdown brief, one block per theme under `blog-manager/themes/`, with no `__resolveType` so the site never resolves it. One block each rather than an array in one block: appending five suggestions can't clobber the one being edited. BLOG_THEME_SUGGEST proposes them from the brand context, the titles already covered, an operator's guidance and an optional web_search hop (which also asks what the named competitors published). Doesn't persist — the web writes the blocks, same contract as BLOG_BRAND_EXTRACT. BlogBrandSchema moves to blog/schema.ts, now shared by both tools. Two concurrency fixes found while wiring it: - The suggestion's writes are sequential. Fired in parallel, each one replaces the whole decofile cache with the server's snapshot in fast-preview mode, so the loser's theme vanished from the list until the next refetch. - Each row owns its own autosave draft. One draft held by the screen for whichever theme is open would let a save still in flight land on the block of the theme selected next, because the callback reads the open key when it fires, not when the edit happened. Batch timestamps are staggered by index so the list keeps the model's ranking instead of re-sorting alphabetically. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Makes the Library's Formats tab real. A format is a name plus a markdown brief that gets injected into the generation prompt — deliberately loose, so it describes intent and lets the model decide the actual sequence. The `@` picker is the discovery mechanism: it lists the sections this site can render, with what each one does, and inserts the component name. That replaces both a block-sequence builder (which would defeat the point) and a checkbox allowlist — a citation is positional, so "opens with a @Heading, closes with a @ProductShelf" says something a set cannot. A mention lands as PLAIN TEXT, not a node. The field round-trips as markdown, and a node would need both renderMarkdown and parseMarkdown — the latter a token matcher for arbitrary `@word`, since the parser runs only the first handler per token. Plain text round-trips for free and stays readable in the block JSON. This needs no schema change: `Suggestion()` is a bare ProseMirror plugin attached with registerPlugin, so the markdown round-trip test is untouched. BLOG_FORMAT_SUGGEST names the formats a blog already writes in. Its load-bearing input is the *shape* of each post — the sequence of section component names — not the prose: 40 of those sequences are a tiny input and the only part that answers "how is this post built". With no `smart` tier it reports fallback:true and the web writes a starter format of its own, which needs no model and so can be localized. Three things found while wiring it: - `discoverBlogBlockTypes` dedupes by resolveType, so app and site variants of one component both survive — which collided on the picker's React key, and is meaningless anyway once a citation is the bare name. `mentionableSections` collapses them. - The orphan-citation warning used `text-warning-foreground`, which is near-white (it's for text *on* a warning fill) and would have rendered invisible. Every other call site uses `text-warning`. - That warning also ran its callback twice per open row. The chat's Suggestion gains optional renderItem/emptyLabel; without them its behavior is unchanged, which its own tests cover. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Brings in post scheduling (#6421), which lands as its own Scheduling row under Blog — outside Conteúdo autônomo. Conflicts, both additive: - collections-sidebar: keep both new rows, Scheduling then Autonomous. - blog-data.test.ts: import block only, keep both sides' symbols. main replaced `isPostPublished` with `postStatus` and `PostMeta.published` with `PostMeta.status`; nothing on this branch read either, so the rewrite came through untouched. Regenerated the tool contracts: the auto-merge of tool-io.ts had dropped `threadId` from RepoFileParams (#6383). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Its placeholder promised "generated posts on a calendar, so you can schedule them" — which #6421 now delivers as the Scheduling row under Blog. A placeholder that describes a feature shipped somewhere else is worse than no placeholder. Conteúdo autônomo is Themes and Library, opening on Themes. Deleted the three orphaned sandbox.planner.* / collectionsSidebar.planner keys in both locales; tsc caught the Calendar and EmptyMessage imports it orphaned. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…input reading as search Five fixes to what shipped in the last two commits. The three AI buttons behaved three different ways with no provider connected. Brand extract and theme suggest threw TierUnavailableError, which tools-rest maps to a 500 and the web surfaced as a raw English toast; format suggest silently returned a starter template instead. All three now check `useHostedAiProviderKeys()` and disable with a title pointing at Settings → AI Providers. `resolveTier` never checks a balance, so an org with a provider but no credits still fails inside `generateObject` with whatever the provider says. That is unchanged — there is no cheap pre-flight for it — but it is now the only unguarded case rather than one of several. The starter format becomes its own always-available button. It is static text needing no model, so making it a hidden consequence of billing state was wrong: the same click did different things depending on something the user can't see. BLOG_FORMAT_SUGGEST drops its `fallback` output field and goes back to `resolveTier`, so all three tools now fail identically. The theme guidance input sat alone above the list, empty, with a grey placeholder — exactly where a filter would live. It read as a search box, and typing in it fired a generation. It moves into a popover on the button, where it only appears at the moment it applies. Also: SaveStatus had three hardcoded English strings and is used by nine sandbox editors, and the pt-BR themes subtitle said "virá a ser". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`RuleList`'s add button appends `{ name: "", value: "" }`, and the render
pipes the list back through `normalizeBrandRules`, which dropped any entry
with no text — so the new row was deleted before it ever painted. The
button did nothing.
The Formats tab is where this surfaced, because adding by hand is the only
way to get a row there. It was equally broken for the four brand-context
rule lists; nobody hit it because those get filled by the extract.
That `untitledRule` label already existed for a row with no name yet, so
showing the blank row was always the intent — the normalizer was quietly
defeating it.
An object entry now survives with both fields empty. Only a non-object, or
a blank legacy string, is still junk. The two callers that mean substance
rather than editor state — the tool inputs, and the extract's
"is this field still empty?" guard — go through the new `filledBrandRules`;
without that, adding a blank row would have made the extract skip that
field in silence.
Inverted the test that pinned the old behavior rather than adding beside it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
New Gerar tab, and the tool behind it. Novo walks four steps — theme, format, when it goes live, any last instruction — and writes a post block with `status: "scheduled"`. Never published: a human reviews it, and the schedule is what they opted into. Brand context blocks generation rather than warning about it. Without the basics, the generation rules and the guardrails, the model falls back on what a brand in this category usually sounds like, which is the one outcome this whole feature exists to avoid. The blocked screen names the missing fields. `values`, `categories` and `competitors` stay optional. A step with nothing to pick from shows the writing surface plus a Suggest button, so a site with no themes and no formats can still answer it. What gets written there is persisted as a theme / format, since it is the same thing those screens hold. The design decision underneath: the model names section kinds and the client owns everything site-specific. Only the site knows whether Heading is `blog/sections/blocks/Heading.tsx` or its own `site/sections/Blog/Post/Heading.tsx`, so the model never sees a resolveType and cannot invent one. Three traps found by reading the block editors, all of which produce a block that saves fine and renders empty: - `List` stores its items as one newline-joined string, while Checklist, StatGroup, Steps and Comparison store JSON — `str()` on a real array yields "". Each kind is written out explicitly, and tested. - Paragraph holds `html`, not markdown. - Heading/List/Callout enums are defaulted rather than left undefined. Generation covers only text-shaped sections. An image or a product shelf needs data no model can invent, so those stay for the reviewer — which is also why `image` is left empty and `missingPostFields` reports it. The draft section schema is a flat object with a `type` enum rather than a discriminated union: the caller has to validate and drop sections anyway, so the union bought no safety while pushing `anyOf` through structured output, which works on three providers and fails on the fourth. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Four conflicts. Three were textual; one was not. main added its own `@` picker to MarkdownEditor — org members, inserted as a node that serializes to a markdown link, with a store bridging the ProseMirror plugin to a cmdk menu and three follow-up fixes for focus, portalling and dismissal. Both answer to `@`, and main installs its store unconditionally, so in the format editor the two would have fought over the trigger. Resolution: `markdownEditorExtensions` gets the store only when no item list was passed, so a field listing its own items installs one picker and a task description installs the other. Mine is renamed SectionMentionMenu and carries a `ponytail:` note — folding the two together means making main's item source, item row and insert all injectable, which is worth doing but not mid-merge in a file under active change. The section citations still round-trip: main's mention parses from a link href, and a bare `@Name` is not a link. i18n was additive on both sides. tool-io.ts is generated, so it was resolved by regenerating rather than by editing — 191 contracts now. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
No conflicts: main's three markdown-editor fixes (ordered lists, table and checklist schema, caret-is-not-an-edit) landed in files and hunks this branch doesn't touch, and my SectionMentionMenu came through intact. `node_modules` needed a clean reinstall, not a code change. main's #6663 consolidated the lockfile onto @tiptap/pm 3.30.5, but the 3.20.2 tree was still on disk, so two copies of prosemirror-model resolved at once and tsc failed on main's own mention-suggestion.tsx with an unassignable Node. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an Autonomous content collection to the Content tab (Blog group), holding the brand context every generated blogpost will be written against: tone of voice, generation dos and don'ts, audience, values, blog categories, competitors.
Persists to the site's own
.deco/blocks/blog-manager-brand.jsonas plain JSON — no new table. Same path and field names Spire writes, so a site it already set up opens here populated.BLOG_BRAND_EXTRACTfills the empty fields by reading the site's own CMS blocks.No scraper, no new credential
The first draft called Firecrawl. That was wrong:
FIRECRAWL_API_KEYis an instance-wide env var, so someone on the hosted Studio can neither enable it nor bring their own key, and the cost lands on a shared quota. Reading a URL server-side would also have needed an SSRF guard we don't have (httpUrlSchemaonly rejects non-http schemes).The blocks are already in the browser's decofile, so the tool takes them as input and only calls the model. Inference runs on the org's own
smarttier viaresolveTier— same path assuggest-commit-messageandjudge-requires-review— so it bills to the org, and the org picks the model.Two things the real data forced
Tested against a real storefront's 1969 blocks:
extractBlockProsewalks a block and keeps onlyprop: phraselines (a phrase = contains a space), deduped, which separatesalt: "92% de funcionárias"fromsite/sections/Layout/Flex.tsxand20pxwithout a prop allowlist.The prompt also encodes traps found in that data: internal asset annotations (
[LP … ] [carrossel …]) are not copy; shipping/return/payment fine print is not editorial voice; brand-specific vocabulary (a site calling the shopping bag mochila) is the most valuable thing to capture verbatim; and casing is part of the voice, including when it's inconsistent.Won't clobber hand-written rules
Re-running the extract writes only into fields that are still empty, so it can never wipe dos/don'ts someone typed. The toast reports how many it filled, or that there was nothing to fill.
Testing
62 unit tests in
blog-data.test.tscover the prose walker (drops URLs/identifiers/dimensions, keeps phrases and prop names, dedupes exact repeats, preserves casing variants) and the evidence ranking (tier order, prose-density ordering, char budget, empty site, missing page keys).bun test apps/api/src/tools/reports 25 failures — pre-existing: the same 25 fail on a clean tree (verified viagit stash -u), and each file passes in isolation, so it's cross-file test pollution unrelated to this change.tsc --noEmitclean in both workspaces,knipclean,lint0 errors,fmtapplied.Not in this PR
writeroute off-cluster, so local verification needsDISABLE_ORGFS_MOUNTS=1. Unrelated to this diff.selfhost/examples/dev-hybrid/.env.examplestill shipsSTUDIO_SANDBOX_PREVIEW_URL_PATTERNset, which 502s every daemon call off-cluster. Out of scope here; worth its own fix.🤖 Generated with Claude Code
Summary by cubic
Generates scheduled blog post drafts from a selected theme and format, completing the Autonomous content flow. Drafts never auto-publish and generation is blocked until required brand context is present to preserve voice consistency.
BLOG_POST_DRAFT: builds text-shaped sections (Heading, Paragraph, List, Quote, Callout, Cta, Divider) and writes a post block withstatus: "scheduled". The client maps section kinds to site components; unknown or unsupported kinds are dropped.smarttier; all three buttons disable with a tooltip when no provider is connected..deco/blocks/(blog-manager-brand.json, themes, formats, posts). SaveStatus is localized; mention picker supports plain-text@ComponentNamecitations and warns on unknown citations.@; each field installs only the one matching its item source, so they never conflict.Rollout
string[]rules; extraction and suggestions remain idempotent on non-empty fields.Written for commit c904ffb. Summary will update on new commits.