Repository navigation
fix(content): low items from the Content stack review - #1314
Conversation
Content Editor CE-001 and CE-002. Content becomes a group in the sidebar, like Prompts: Opportunities keeps /dashboard/content, and the new Library (/dashboard/content/library) lists every page a person or the Content Agent writes or changes in Ansvisor, by status (Drafts, In review, Ready, Published), with its page type, method, author and AEO score. - Migration 00203: content_drafts with member RLS (select, insert, update; no delete yet). A guard trigger keeps author, created_by, brand and the scores server-side, so a member can't pass a draft off as the agent's. - Sidebar: each submenu remembers its own open state (Prompts keeps its key), and only the longest matching entry is current, so Opportunities isn't marked on the Library. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor CE-004, stacked on the Library (ansvisor#1256). A draft opens at /dashboard/content/editor/{id}: a header with its title, page type, method and status, whether it's saved, and Mark ready; the toolbar (H1 H2 H3, bold, italic, link, lists, quote, table with add row / add column / delete, image by address) with the length counter against the page type's target; and the page as rich text (TipTap 3.31.4, pinned). - Autosave after a pause in typing; saves never overlap, a failed one keeps the text and offers Retry, and leaving with unsaved text asks. The draft's title is its first H1. - saveContentDraft validates the body (500k chars) and title and says when RLS matched no row; markContentDraftReady moves draft or in review to ready only. - Links: http(s), mailto or a path on the brand's site; javascript:, //host and /\host are refused, in the dialog and when content loads. - The Library gets New content (a blank draft, until the Start screen), and its entry stays current while a draft is open in the editor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Content Editor CE-005 and CE-020, stacked on the editor core (ansvisor#1258). - Paste: from Word, Google Docs, Notion or a web page, headings (H4-H6 as H3), paragraphs, bold, italic, lists, links, tables and quotes stay; fonts, colors, classes, inline styles, scripts, iframes and utm_*, gclid, fbclid on links go. Google Docs' styled bold and italic become strong and em first. Pasted images wait for attachments. Cmd/Ctrl + Shift + V pastes plain text. - </> HTML shows the page's HTML as a draft stores it, one block per line; Back to visual cleans it with the same allow-list and says how many unsafe tags it removed. Schema JSON-LD is kept: a block in the editor, written again from its JSON so it can't carry markup. - The server checks every save against the allow-list again (sanitize-html), so a request made without the editor can't store a script, a handler or a javascript: link. - dompurify 3.4.16 and sanitize-html 2.18.0, pinned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
sanitize-html 2.18.0 needs Node 22.12 or later, and CI and the web Docker image run Node 20, so yarn install refused it. 2.17.0 has no engine limit and the same API; @types/sanitize-html 2.16.0 matches it (both on htmlparser2 8). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Links in a draft looked like the text around them (dark, barely underlined), so a link just added seemed not to be there. They're blue and underlined now. With the cursor in a link, the toolbar shows its address, which opens it in a new tab; Cmd/Ctrl + click on it in the page does too. A click alone still puts the cursor in it to edit. A path on the brand's own site is shown, not opened: it has no address here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-html # Conflicts: # web/messages/en.json # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
On the user's request, as Webflow's custom code in rich text: as many HTML blocks as a page needs, each carrying code as written (an embed, a widget, a form), and one-click Copy HTML for a block or the whole page. - An HTML block is added from the toolbar where the cursor is, and edited or removed from its own Edit. The editor shows its code as text; it never runs in Ansvisor. A draft stores it as UTF-8 base64 in an empty element, so no markup in it can act, and the server checks each one decodes and fits 50,000 characters. - Copy HTML (header) puts the page on the clipboard as HTML to publish: each block as its own code, schema JSON-LD as its script. A block's own Copy HTML copies just its code. A refused Clipboard API falls back to the browser's copy command. - The HTML view shows each block between <!-- html-block --> markers, kept as written; code typed between new markers becomes a block. A paste from elsewhere can't bring blocks in. - The link, image and block dialogs focus their field when they open. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…locks # Conflicts: # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_toolbar.tsx # web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
Inserting an HTML block scrolls the cursor into view, and ProseMirror measures a Range to do it. jsdom's ranges have no getClientRects, so on CI's Node 20 the measuring threw on a timer after the test and failed the run as an unhandled error. The editor test gives ranges an empty measurement, as jsdom has no layout anyway. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es to a draft A paperclip tool and drag-and-drop on the editor (CE-006). Excel and CSV open a preview (sheet picker, first 10 rows, header row) and insert as a table, asking first above 200 rows. Word (.docx, via mammoth), Markdown, HTML and plain text import as content through the same cleaning as a paste. Images, old .xls/.doc and files over 10 MB get a clear message. Imports land under a table when the cursor is inside one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Page types follow the kind of site (CE-023). Brand settings get a Site type (B2B SaaS, E-commerce, B2C; guessed from Shopping mode and the industry until picked), stored in brands.site_type (migration 00205). A draft's page type is detected from its URL, JSON-LD schema and title, and kept in step as the page changes, until the person picks one from the editor header's page type menu (content_drafts.page_type_source). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rary # Conflicts: # supabase/schema.sql
ansvisor#1257 took 00203 (citation gap rollups) on main, so the content drafts table moves to the next free number. The file is otherwise unchanged; schema.sql is rebuilt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
New content (CE-003) starts a page from an open Content Opportunity, a tracked prompt or a topic, or brings content to optimize by pasting (cleaned like the editor's paste) or uploading a Word, Markdown, HTML or text file. Start (CE-015) offers the site type's page types, the one the title or content shows picked first, and opens the editor. The draft keeps the opportunity it came from and the prompts it should answer (migration 00206: opportunity_id, prompt_ids, and a trigger that refuses another brand's opportunity or prompts). A new page starts with its title as the H1; content to optimize is checked against the draft allow-list. The editor's file readers move to lib/content/import-document so both use them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Start (CE-015) now shows which of the brand's own pages AI already cites for the prompts a new page would answer: prompts in common, citations in the last 30 days and the Google position from Search Console, through a new security-definer RPC, content_page_overlap (migration 00207). It recommends one option: optimize a page that already answers half the prompts or more, otherwise create the page and link the others to it, or say it is safe to create. Picking an existing page makes the draft that page's: optimize, its title as H1, the page type read from its address, and its URL kept in content_drafts.source_url, which the editor shows beside the page type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Optimize content gets a Page URL option (CE-003), and Start's "Optimize this page instead" now brings the page's live text. The API reads the page through a new guarded fetch (server lib/safe-fetch.js): - http(s) on the web ports, no credentials in the address; - every address the host resolves to must be public, checked in the connection's own lookup, and an address written as an IP checked before it, since a literal skips the lookup; - redirects followed by hand and checked the same way; 10 s, 3 MB, HTML only. POST /api/content-pages/import reads only the brand's own domains, before and after redirects, and returns the page's main content, title and JSON-LD (lib/page-content.js). The web cleans it like a paste and reads the page type from the address and the content. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…team Start's Who does it (CE-015): Me opens the editor; Agent waits for the Content Agent; Team sends the draft to the Action Center as an action for someone on the team to write. The API gets a person-sent action kind, content_draft (from-content-draft.js, POST /api/action-center/content-drafts): a new page's or an existing page's library tasks, as an opportunity's page gets, prioritised and measured on the draft's prompts and page. The draft records its action (content_drafts.action_id, migration 00208, server-set: the drafts guard is redefined to keep members from writing it). The Action Center names it "Write: …" / "Optimize: …" and links back to the draft. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The editor gets its right side panel (Content Editor spec v2 §6), with the Impact tab first (CE-016): for the live page a draft optimizes, the last 7, 30, 90 or 365 days against the period before. - content_page_impact (00209): citations on the brand's own domains, AI visits by ai_traffic_merged's rule (snippet on its days, GA4 otherwise), Search Console clicks with the first day of page data, the prompts citing the page in either window with their platforms, and the brand's other pages cited for the same prompts. Security definer with an organization check; whole UTC days, today included. - Impact tab: four cards with their change (low sample under 30, as the AI Traffic page), prompts cited with the lost ones marked, "See in Citations", the overlap line and where the numbers come from; a new page says there is nothing to measure yet. - The panel opens beside the page on a wide window, closes from the header and remembers the choice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the page's AI visits
normalize_page_path('') is '/', so a GA4 row with no landing page read
as the home page's visit.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mpact tab The Impact tab (CE-016, spec §7) now shows what visitors from AI assistants did after landing on the page, and which assistant sent them. - content_page_results (00210): per AI source key, the page's AI visits by ai_traffic_merged's rule (they add up to the AI visits card) and Google Analytics' AI sessions landing on it, with key events, sessions with a key event, purchases and revenue; whether a property is mapped and whether it reported purchases in the window. Security definer with an organization check, same window as content_page_impact. - Results from AI visits: key events and key event rate (low sample under 30 sessions), plus orders and revenue when the property reports purchases; a table by AI source (visits, key events, revenue), one row per platform name with unnamed keys as Other. Without Google Analytics, the visits per source and a link to AI Traffic to connect it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ces tab The editor's side panel gets its Sources tab (CE-008, spec §10): every source the draft draws on, by name, with where the draft uses it. - content_draft_sources (00211): over the last 30 days, the draft's prompts and those whose answers cited its page, the searches AI ran for them (prompt_results.search_queries), the pages their answers cited, the brand's Search Console queries, and the brand and competitor domains. Security definer with an organization check through the draft's brand. A table of the same name keeps a person's choices: a source left out, a page or query added by hand (member RLS through content_drafts). - Sources tab: "Built from N sources" with counts per group; Prompts, Fan-outs, Cited pages (kind named by the citations classifier) and Search Console (queries sharing half their words with the draft); each row with a checkbox, its numbers and where the draft uses it now — a heading or paragraph carrying three quarters of its words, an outbound or internal link, or this page. - + Add source: a prompt joins the draft's prompts; a page address or a Search Console query is kept as added by hand. - The panel opens Sources only when its tab is picked and keeps a tab mounted once opened. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… from the sources kept The editor's side panel gets its Brief tab (CE-007, spec §10), between Impact and Sources: the page type and target address, then the goal, audience and length, and an outline whose H2s each answer a search AI ran (a fan-out) on a platform. - Rebuild outline: POST /api/content-drafts/:draftId/brief writes the brief from the sources the person kept in Sources (sent by the web; the server keeps only the brand's prompts), the page's headings and the length its type asks for. An H2 keeps a fan-out only when it is one kept, with a platform that ran it. Metered from the organization's AI usage (enforceImproveQuota, prompt_improve_usage), not the content brief quota, which stays with Opportunities' Generate Brief. - Migration 00212: content_drafts.brief (jsonb, 64 KB at most) and prompt_improve_usage.content_draft_id. - Edit brief changes the goal, audience, sections, key points and keywords by hand, keeping each H2's fan-out; a draft without a brief shows the brief of the opportunity it started from. - Sources gets "Rebuild with selection", and Impact "Use lost prompts in this draft" (they join the draft's prompts); both rebuild the brief and open it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… tab
The editor's side panel gets its Rules tab (CE-009, spec §10): the rule set
for the page's type — its own rules, then length and structure, fan-outs
and keywords, links and sources, style — each with an on/off switch, a
value the person can change for this draft, and its status read live from
the page as written.
- lib/content/rules.ts: the default sets (spec §10) and their checks:
sentence length, length (the editor's count), the summary under the H1,
the answer under each H2, the top fan-outs kept used as H2s, the FAQ and
the fan-outs in its questions, keywords (the brief's by default),
internal links, outbound links to non-competitor sites, a dated data
point in the first 100 words, inline citations, AI traces, banned words,
and the page types' own (tables, proof per section, steps, fit
questions, intro length, best time). Tone, language and the like say
"AI check", the product feed rule "Needs feed"; neither is counted.
- Migration 00213: content_drafts.rules keeps only what the person
changed: the set's page type and per-rule {on, value}.
- The header's chip "Rules met/total" opens the Rules tab; on a narrow
window it and Copy HTML go short so the header stays one line.
- The length goal comes from the Length rule: the toolbar's counter, the
Brief tab and Rebuild outline use it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The route test loaded the real content-brief module, whose Supabase client exits the process without credentials, as in CI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A save whose answer was lost sends its page along with the next save, which takes a match as the editor's own write instead of a conflict (ansvisor#1258). - A sheet's table allows for each column's width as the editor saves it (ansvisor#1261). - The editor keeps the last detected page type while the page shows none, starting from the stored one, as a save does (ansvisor#1286). - Use lost prompts hands its fresh sources read to the editor instead of reading them again (ansvisor#1294). - A decision saved while the page changed makes its page change again on the page as it is now; what no longer fits goes back, saved too (ansvisor#1303). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk This is the follow-up the overview on #1256 asked for: the low items from both review rounds (#1256, #1258, #1260, #1261, #1286, #1293, #1294, #1295, #1301, #1302, #1303), stacked on #1310. Its own change is the last three commits (38f6944, b03c791 and the merges between them). Checked on top of the stack: server 2,002 tests, web 2,400 tests, tsc, lint, Prettier and |
The PRs below this one are squash-merged on main; this keeps only this branch's own change on top. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
left a comment
There was a problem hiding this comment.
Merging this with the stack. Items 1 and 2 below are small; please take them in your next follow-up PR. The rest checks out. Every low item from both rounds is covered: the upper-case scheme from #1302 was already fixed lower in the stack, and the title-limit comment from #1258 was fixed earlier. There is no migration and no new dependency, and both merges are clean.
-
The lost-save hash isn't the hash of what the server stores (
_use-autosave.ts:110;web/src/lib/actions/content-drafts.ts:864,:917).- The client hashes the editor's raw HTML. The server compares that hash with the stored
body_html, which is thesanitizeDraftHtmloutput. - sanitize-html rewrites most real pages:
<br>becomes<br />, and images also end in/>; becomes a raw U+00A0;- links lose
targetandrel; - tables lose their
styleand<colgroup>.
- On those pages
unconfirmedHashnever matches, so a lost answer still ends in a conflict. The test passes only because<h1>Mine</h1>comes through sanitizing unchanged. - Fix: in that catch, hash the page as the server stores it:
bodyHash(sanitizeDraftHtml(content.bodyHtml)). Import the sanitizer lazily there so it stays out of the editor bundle. - Cheap extra on the server: also accept
currentHash === await bodyHash(bodyHtml). If the database already holds the page being saved, that's never a conflict. - Add a test whose page has a link or a
<br>.
- The client hashes the editor's raw HTML. The server compares that hash with the stored
-
The redo can be dispatched onto a page that changed again (
_draft-editor.tsx:490-504).- When some suggestions no longer fit,
redo.tris built first. Thenawait decideDraftSuggestions(redo.failed, back)runs with the editor editable again. - If the page changes during that call,
dispatch(change)throws "Applying a mismatched transaction". The person sees the save-failed toast, the page and the cards stay as they were, and the rows are already saved as decided. - Fix: dispatch
redo.trright after building it, before the second save.
- When some suggestions no longer fit,
-
Optional: the type update after a restore (
content-drafts.ts:1071) isn't tied to the restored version. If another write lands between the read-back and that update, itsupdated_atbecomes the editor's base, and the next autosave writes over it. Add.eq('updated_at', restored.updatedAt). The type update after a save (:889) has the same gap; tie it todata.updated_atthere. -
Nit:
web/src/lib/content/rules.ts:243:ruleSet's doc comment now sits abovelanguageRuleValue's. Move it down toruleSet.
Summary
The low-severity items from @gkhngyk's review of the Content stack (#1256 … #1309), collected in one follow-up PR on top of the stack, as the overview on #1256 asked. Stacked on #1310: the diff against
mainincludes the stack until it merges; this PR's own change is its last commit.getContentDraftsnow returns{ drafts, counts }. Under the 500-row cap, the counts come from the rows. At the cap, each tab is counted with acount: 'exact', head: truequery. When a tab holds more than it lists, the Library says "Showing the N changed most recently of M."OwnCopiesextension sets aclipboardSerializerthat marks this editor's copies with a per-tab nonce (data-ce-copy).transformPastedHTMLkeeps images and HTML blocks only for a paste that carries the nonce, then strips the marks before cleaning.data-pm-slicealone no longer counts, so a paste from another ProseMirror/TipTap site (or a page's copy handler) can't plant an HTML block.topicswithprompts(count), active prompts only), not from the first 500 prompts listed.edit, Rebuild outline shows "Rebuild outline writes a new brief over the one you edited." with Rebuild anyway / Keep my brief.ruleSettakes the brand'slanguage(languageRuleValue: the language's name, US English for English or none). The editor and Start's agent request pass it.storedBytesmeasures the JSON as jsonb stores it and errs high.draftRulesFit/ruleSetFitscheck the 32 KB / 16 KB / 32 KB limits from 00213 / 00214. The editor refuses an over-long change with "These rules are too long to save…" instead of a generic failure, and the actions refuse it too (too_large). For example, 40 rules of 300 CJK characters pass zod but not the check.restoreDraftVersion(id, versionId)re-detects the type on the server when the draft's type follows its page, writes it as a save does, and returns the newerupdated_atfor the version check. It reads the draft back first and only does this when the restored body is that draft's.insertTextfor a character, or deleting the selection or the one character beside the cursor within its block. A key that would join blocks is still pressed again. Edit anyway applies that change.From the second review round:
unconfirmedHash. The server takes a page matching either hash as the editor's own write, so autosave doesn't stop on a conflict.<col style="min-width: 25px">) plus 100 for the wrapper.onSourcesRead) instead of being read again.redoDecision). Suggestions it no longer fits go back to their earlier status, and that is saved too.Not here: #1308's
(url_id, brand_id, created_at)index (only if the overlaps read is slow on prod) and #1309's per-URL page sign (longer term).Related issue
Follow-up to the reviews on #1256, #1258, #1260, #1261, #1286, #1293, #1294, #1295, #1301, #1302 and #1303.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
data-pm-sliceand adiv[data-html-block]pasted from elsewhere loses the block.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
yarn test(2,400 tests) andyarn build. No new dependencies, no migration.🤖 Generated with Claude Code