Repository navigation
feat(demo): fill the demo brand's Action Center, content, suggestions and reports (demo brand, part 2) - #1735
Merged
Conversation
… counts Migration 00380 adds brands.is_demo, demo_version, demo_built_at and demo_hidden_at, one demo brand per organization (partial unique index) and policies that let members read it but never insert, change or delete one. The plan's prompt-location quota, the usage cards' account totals and the web's brand limit leave the demo brand out; the health report's fan-out share leaves out its answers. The brand delete route refuses it: the demo brand is hidden, not deleted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The daily tracking list, the job claim and recovery (activeBrandFilter / isBrandActive), the signal catch-up, the pulse, the task writer, executor and checks, action validation and Improve outcomes, the Insights sweep, brand facts, Search Console and Analytics syncs, page opportunities, the traffic digest, auto-audits, catalog feeds, Webflow status and volume analysis all leave demo brands out: their data is sample data and nothing may track, write or spend for it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
lib/demo/ builds an organization's demo brand in its own brands: Brewline
Coffee (brewline.example) with fictional `.example` competitors and
publishers, 12 prompts in 3 topics, 6 engines and a run every 3 days over
a month (720 short answers) with citations, product cards, searches and
volumes. Answers are raw engine responses run through tracking's own
parseScraperResponse, parseResponse and the result and shopping card rows
(now pure resultRow and shoppingCardRows in cloro-result-handler.js), and
the rollups are rebuilt by the nightly run's own functions.
ensureDemoBrand creates it, rebuilds it in place (same ids) when
DEMO_VERSION moves on or its data is three days old, and leaves it alone
otherwise; concurrent visits share one build (one-per-org index, a
compare-and-set claim, a lease). Modules are { name, tables, build }, and
a coverage test fails on any brand_id table the demo neither builds nor
lists as skipped or pending.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /api/demo creates or rebuilds the organization's demo brand for any
member and returns { brandId, version, rebuilt }; PATCH /api/demo
{ hidden } hides or shows it for admins and managers ({ brandId, hidden },
404 no_demo without one). Both stay open once a plan has ended.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s and reports Four demo modules over core's answers: signals and a month of actions (tasks, trail, measured outcomes, a task waiting for review, ready-made KPIs, Getting started with its page steps opened), prompt clusters, content opportunities, Editor drafts and Plan marks, prompt, topic and Improve suggestions, and two saved reports. Numbers are counted from the demo's own answers; shapes come from the engine's own functions. detect.js exports single and promptTarget so the demo writes signals in their shape. Co-Authored-By: Claude Opus 5.5 <[email protected]>
DEMO_MODULES runs core, suggestions, actionCenter, content and reports; DEMO_VERSION 2 rebuilds existing demo brands on their next visit. The coverage lists move the workflow tables to built, skip the engine's internal queues and logs and the org-level author default, and leave the draft shopping check to demo-site with the catalog. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first module lays down what the others point at; the rest write their own tables together, each after the module it names in `after`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # server/src/lib/demo/index.js
A first build no longer clears 70 empty tables, and the core writes each step's independent tables side by side through a shared queue of four statements (write.js: insertChunks, demoWriter). Its rollups move to a refresh step that runs alongside the other modules, Insights, Citations and Mentions together, the month's answer terms in one call (refreshMentionsDaily takes an optional termDays). The core alone went from about 17 s to 7 s on the dev database. A rebuild (new DEMO_VERSION, or data older than three days) no longer deletes the demo first: an `inPlace` module writes over its rows by key (ids are deterministic) and deletes only the rows it didn't write again, then rebuilds the rollups over the old and new days, each refresh call rewriting its days in one statement. Someone opening the demo meanwhile sees last week's data, not empty pages. Modules not marked `inPlace` still have their tables cleared, now just before they are built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand just created isn't empty: its insert trigger starts Getting started, so skipping every clear on a first build made the Action Center's insert hit getting_started_pkey. An in-place module now always writes over by key (the first build only skips reading back and pruning); a module that isn't rebuilt in place clears its own tables just before it is built, on a first build too, alongside the other modules rather than all up front. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…irst build Nobody looks at a demo being built for the first time, so every module not rebuilt in place starts clearing what the new brand's triggers made at once, while the core writes, instead of each in turn later, when its deletes queue behind the rollups. A rebuild still clears each module just before it is built, so its old rows stay on show as long as they can. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # server/src/lib/demo/index.js
A table with an identity id and no other unique columns (ai_bot_events)
can't be written over by key. write(table, rows, { generated: true })
inserts the new rows and, on a rebuild, deletes the brand's rows that were
there before right after: never empty, both there for a moment.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts in place The four workflow modules write through the build's writer (ctx.write): each step's independent tables side by side, and on a rebuild over their old rows by key, deleting only what isn't written again, so their pages never empty while the demo is rebuilt. Keys where a row has no id: getting_started (brand_id, also what a new brand's trigger made), getting_started_steps, action_signals, the cluster members, searches and scopes, and the plan marks; the action and cluster children are found through their parent (scopes). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
refreshMentionsDaily takes `together`: the rollups (refresh_mentions_daily) and the answer terms (refresh_mention_terms) take their own locks and write their own tables, so the demo runs them side by side instead of one after the other, a second off the longest step of its build. The nightly run keeps them in turn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…core # Conflicts: # server/src/lib/action-center/task-checks.js # server/src/lib/action-center/validate.js # server/src/routes/index.js # supabase/schema.sql
…ver main's new tables sweepPromptDemand chose brands by their organization's plan only, so an active workspace's demo brand would have had its sample prompts read and DataForSEO's paid tasks set for them. It now leaves demo brands out, as the other sweeps do. The demo coverage list names the two brand tables main added: prompt_table_views (skipped: the demo starts on the default columns) and prompt_demand (pending a demo follow-up). Co-Authored-By: Claude Opus 5.5 <[email protected]>
7 of 8 tasks
6 tasks done
…core # Conflicts: # server/src/lib/action-center/execution/run.js # server/src/lib/action-center/execution/run.test.js # supabase/schema.sql
…n's new tables sweepCompetitorTimeline (learning C3, on main) chose brands by their organization's plan only, so a demo brand's sample answers would have had their cited pages read every night. It now leaves demo brands out, as the other sweeps do. The demo coverage list names the brand tables main added: cited_page_features, competitor_page_events and competitor_timeline_scans (pending a demo follow-up) and chat_conversations (with Chat). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chat's precedence (ansvisor#1776) left readBrandIsDemo false until the demo chain added brands.is_demo, with a type check that stops compiling once the column exists. It now reads the column, as the server's demo guard does, so a tool that changes or spends on the demo brand is refused with demo_brand; a brand that isn't found isn't one, and a failed read throws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups
Reviewed ebe6378 (part 2), as its own diff on top of #1734's head 85ccbe6. No migration. Outside lib/demo it only exports single and promptTarget from signals/library/detect.js; nothing else there changes.
What I checked
- It writes only the demo brand's own rows. Action Center, Content, suggestions and reports write through the build's writer:
- Every id is
demoId(brandId, …). - The keys that aren't
idincludebrand_idor a parent of the demo (getting_started_steps: brand_id,step,action_signals: action_id,signal_id,prompt_cluster_scopes: brand_id,topic_id,content_plan_marks: brand_id,row_key). - The tables without a
brand_id(action_tasks,action_events,action_task_reviews,action_signals,prompt_cluster_members/queries) are found and pruned only through the demo's ownactionsandprompt_clustersids.
- Every id is
- Nothing it writes starts work. These rows are written directly, not through the engine, so no webhook, e-mail or model call follows. The nightly passes that would read them leave a demo brand out: the task writer, task checks, execution, validation and Improve outcomes (part 1), and the signal catch-up through
activeBrandFilter. - No usage table is written.
prompt_improve_usage,opportunity_usage,brief_usageandsuggestion_relevance_usagestay empty for the demo, so the AI usage meter, the opportunity quota and the brief quota don't move. - Coverage:
action_candidates,action_task_runs,signal_runsandcontent_author_defaultsare skipped with reasons that hold. Getting started is written over bybrand_id, so the row the brand-insert trigger made is reused. - Tests:
src/lib/demopasses on this head and on the stack merged with main.
Merging main. Same three conflicts as #1734 (execution/run.js, its test, schema.sql). They are resolved on the branch noted on #1736.
Follow-ups
- The demo's content drafts and suggestions are ordinary rows. Until part 4's write guard lands, a member can edit them, accept a suggestion or run one, and the server's paths that cost (brief, Improve, refresh) take a demo brand like any other. Please merge parts 1–4 together, not part by part.
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.
Summary
Demo brand, part 2 of 7 (server). The demo brand's Action Center, Content, suggestions and reports, as generator modules beside the core. The demo moves to
DEMO_VERSION = 2, so every demo brand is rebuilt on its next visit.lib/demo/action-center.js): signals, the actions raised from them over the month with their tasks, history and measured outcomes, the KPI framework, a task waiting for review, and Getting started.stats.js), in the detectors' shapes. Actions are built the waygenerate.jsbuilds them (payload,planTasks,scorePriority). Closed ones are measured asvalidate.jsmeasures them (basketValues,deriveOutcome).signals/library/detect.jsexportssingleandpromptTargetfor this; nothing else changes there.content.js,content-pages.js): prompt clusters (stored asreplace_prompt_clustersstores them, so nothing reads them as stale), content opportunities with the generator's own metrics, score and assets, Content Editor drafts and Plan marks.suggestions.js): prompt, topic and Improve suggestions.reports.js): a weekly visibility summary and a competitor benchmark, with the web'sReportPayloadshape and numbers counted from the demo's answers.PENDINGto built.action_candidates,action_task_runs,signal_runsandcontent_author_defaultsare skipped, each with its reason.Migration / deploy notes: no migration. Demo brands built at version 1 are rebuilt at the next visit.
Related issue
None (demo brand).
Stacked on #1734 (demo brand, part 1: core).
Type of change
feat— New featureHow to test
POST /api/demo, or pick Brewline Coffee in the brand menu). Its demo is rebuilt at version 2.Checklist
eslint srcpasses. Tests:src/lib/demoandsrc/lib/action-center(39 files, 763 tests) pass.yarn typecheckpasses; billing andsubscription-guardtests pass.🤖 Generated with Claude Code